- Ana opens a note.
- Ben opens the same note, changes it and saves.
- Ana saves the text she started from, and Ben’s change is gone.
Add a version field
Store a counter on the document. Classify it like the table’s other fields:bijection/schema.ts
0 when you insert the document.
Compare it in the mutation
The client sends the version it read. The mutation compares it with the stored version, and the transaction guarantees that nothing changes between that check and the write:bijection/notes.ts
Handle the error in the client
Pass the version the editor opened with, not the latest one fromuseQuery.
A live query updates while the form is open, so reading the version at save time
would hide the change you want to catch:
src/EditNote.tsx