fix(editor): never save a document under a mismatched note id - #18
Merged
Conversation
The editor tracked which note a keystroke belonged to in a ref, resynced only by an effect, while the store held the authoritative id. When the two fell out of step the autosave wrote the open document over a different note, replacing its body. - guard the save path on the store's active id, the check the bubble helpers in the same file already make - stop reloadExternal acting on an `active` captured before its awaits, which could reassign the open note behind the editor's back - archive a note's previous text before any save that discards most of it, under .sudonotes/versions/, so a bad write is never unrecoverable
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
sudonotes-site | ba3033e | Commit Preview URL Branch Preview URL |
Sep 04 2026, 07:59 PM |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
sudonotes-app | ba3033e | Commit Preview URL Branch Preview URL |
Sep 04 2026, 07:58 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ❌ Deployment failed View logs |
sudonotes-api | ba3033e | Sep 04 2026, 08:00 PM |
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
The editor tracked which note a keystroke belonged to in a ref, resynced only by an effect, while the store held the authoritative id. When the two fell out of step, the autosave filed the open document under the other note's id — overwriting that note's body.
The bubble helpers in the same file already guard on
active.id !== activeId.current. The save path did not.Fix
Editor.tsx— the save path now requires the store's active id to match the ref. On mismatch it drops the write and warns rather than persisting under the wrong id. This also stops the persisted undo history being written under a mismatched id.store.ts—reloadExternalre-readsactiveafter its awaits and bails if the open note changed. It capturedactivebefore two round trips and could reassign the open note behind the editor's back.versions.rs(new) — safety net. Before any save that discards more than half of a non-trivial body, the previous file is archived to.sudonotes/versions/<id>/, keeping the last 20 per note. Wired intosave()andupdate_note().Tests
cargo test78 passed (4 new),vitest127 passed,tscclean.