fix: Note content corruption on restart#3
Open
rgcr wants to merge 1 commit into
Open
Conversation
…corruption
The contentChanged debounce timer (300ms) captures currentNoteId at fire time,
not at schedule time. When a note switch occurs between scheduling and firing:
1. User edits note A → debounce timer starts
2. User clicks note B → Swift queues: serializeState(), setCurrentNoteId('B'), restoreState(B)
3. JS executes setCurrentNoteId('B') → currentNoteId = B
4. Debounce fires → sends A's content with noteId=B → overwrites B with A's content
5. restoreState(B) executes → clears debounce (too late)
The corruption is invisible during the session because the in-memory stateCache
still holds B's correct content. But on next launch (or after OS restart), the
stateCache is empty and B loads from the corrupted persisted data.
Fix: Clear the debounce timer in setCurrentNoteId(). This is safe because
serializeState() → cacheSerializedState() already persists the old note's
content before setCurrentNoteId is called in every note-switch path.
f4027ea to
227aeb5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After an OS restart (or app relaunch), inactive notes have their content replaced with the active note's content. The first note's content gets replicated to the others.
Root Cause
The
contentChangeddebounce timer (300ms in JS) capturescurrentNoteIdat fire time, not at schedule time. When a note switch occurs between scheduling and firing:serializeState(),setCurrentNoteId('B'),restoreState(B)setCurrentNoteId('B')→currentNoteId = BnoteId = B→ overwrites note B with A's contentrestoreState(B)executes → clears debounce (too late), loads B's correct content fromstateCacheThe corruption is invisible during the session because the in-memory
stateCachestill holds B's correct content. But on next launch (or after OS restart),stateCacheis empty and B loads from the corrupted persisted data — showing A's content.Fix
Clear the debounce timer in
setCurrentNoteId(). This is safe becauseserializeState()→cacheSerializedState()already persists the old note's content beforesetCurrentNoteIdis called in every note-switch path.Changed files
editor-web/src/editor.js— 1 line added insetCurrentNoteId()