Repository navigation
fix(editor): hand committed edits to edit-sync even when the update throws - #488
Merged
Merged
Conversation
…hrows CodeMirror commits the new state before its DOM phase and wraps each update listener in its own try/catch. A throw from the DOM phase skipped the edit-sync listener entirely, and a throw inside it was logged and swallowed, so a committed edit could stay unscheduled with no sign it never reached the host. Move the edit-sync notification into dispatchTransactions' finally, keyed on doc identity (a throw before the commit leaves nothing to send), and turn a throw from the scheduling step itself into a send failure so the banner shows and the next keystroke retries.
…ot reseed over it
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.
Summary
A committed edit could stay unsent with no sign of it: CodeMirror commits the state before its DOM phase and runs each update listener in its own try/catch, so a DOM throw skipped the edit-sync listener and a throw inside it was swallowed. The edit-sync notification now runs from
dispatchTransactions'finally, and a failure to schedule surfaces as a send failure.Changes
src/webview/editor.ts: move the docChanged → edit-sync hand-off (incl. the send-failure retry ordering) out of the updateListener intonoteLocalChange(), called fromdispatchTransactionsin afinallyand keyed on doc identity (a throw before the commit leaves the doc unchanged, so nothing is sent). A throw fromnoteLocalChangeitself dispatchessend-failure, so the banner shows and the next keystroke'slocal-edit-attemptretries with the whole document.test/webview/editor-unsent-edit-faults.test.ts: fault injection for both arms: a widget whosetoDOMthrows (edit still posted after the debounce), and a wrappedcreateEditSyncwhoseonLocalChangethrows once (send-failure dispatched, next keystroke shipsseedxy). Both tests fail without theeditor.tschange.No paste-specific ACK or resend: this is a property of every dispatch, so the fix sits on the common path.
Related
Test Plan
pnpm vitest run test/webview/editor-unsent-edit-faults.test.ts: red before the fix, green afterpnpm vitest run: 291 files / 6219 tests greenpnpm test:browser: 92 greenpnpm compile, Biome clean