Skip to content

fix(editor): never save a document under a mismatched note id - #18

Merged
dariomory merged 1 commit into
masterfrom
fix/editor-save-note-identity
Sep 4, 2026
Merged

fix(editor): never save a document under a mismatched note id#18
dariomory merged 1 commit into
masterfrom
fix/editor-save-note-identity

Conversation

@dariomory

Copy link
Copy Markdown
Member

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.tsreloadExternal re-reads active after its awaits and bails if the open note changed. It captured active before 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 into save() and update_note().

Tests

cargo test 78 passed (4 new), vitest 127 passed, tsc clean.

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
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 4, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
sudonotes-api ba3033e Sep 04 2026, 08:00 PM

@dariomory
dariomory merged commit 7417f9b into master Sep 4, 2026
7 of 8 checks passed
@dariomory
dariomory deleted the fix/editor-save-note-identity branch September 4, 2026 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant