Repository navigation
Conversation
`_flushOperationCache` cleared the op cache only after the composed batch applied. When compose or apply threw (the block tree and the json state had drifted, as in #4903 / #5148), the failed ops stayed queued and every later flush composed them again and threw: each keystroke raised the error again, and nothing edited afterwards reached the saved document until the file was reopened. Take the batch out of the cache before applying it. When it fails, replace the json state with the block tree's state, which already has the failed edits and which later ops are built from, record the replacement as one undo step (as `Muya.replaceContent` does), and rethrow so the error is still reported once. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01WEPLCvFTgbYf35z85XUJop
Member
Author
|
Closing without merging. This recovers after a failed batch instead of removing the cause of the failure, so we are not adding a recovery path to |
1 task done
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.
Closes #5373
Summary
When one batch of queued edits fails to apply to the json state, the editor never recovers. This happens when the block tree and the json state have drifted apart, as in #4903 and #5148.
JSONState._flushOperationCache()cleared_operationCacheonly after the apply succeeded. So the failed ops stayed queued and were composed into every later flush:Changes in
packages/muya/src/state/index.ts:_syncWithTree()replaces the json state with the block tree's state. The tree already has the failed edits, later ops are built from it, and it is what the user sees.json-change, which the desktop saves. It is recorded as one rebuild undo step, the same wayMuya.replaceContentrecords the source-mode handoff.The drifts known today are already fixed (#5357). This PR limits the cost of the next one to a single error.
Steps to reproduce
On
develop, with a simulated drift in the muya e2e host (packages/muya/e2e) console:second paragraph, press Enter and typethird.first paragraphand typeedited.muya.getMarkdown().muya.getMarkdown()developfirst paragraphfirst paragraph edited/second paragraph/thirdIn the desktop app, with a real trigger. The #4903 steps from #5357 were used, with #5357 reverted locally on both builds because
developno longer has that drift. The 0.20.0-rc.2 packaged app behaves like the first row.jsin the language box, press Shift+↓ and typeq.Outro paragraphand press Enter:Cannot insert into out of bounds index.new, click at the end ofOutro paragraphand typeone.The editor shows
Intro paragraph/jsqnst a = 1/Outro paragraph one/newin both builds.developwith #5357 revertedIntro paragraph/jsqnst a = 1Outro paragraphon screen twice while the document goes back to the originalIntro paragraph/jsqnst a = 1/Outro paragraph one/newType of change
Test plan
state/__tests__/flushFailureRecovery5373.spec.ts(3 cases), all failing ondevelop:json-change;editing/flush-failure-recovery-5373.spec.ts: real keyboard edits after a simulated drift, checking the markdown and that exactly one error is raised. It fails ondevelopand passes with the fix (5/5 repeated).undo-redo,undo-redo-wedge-4685, the Unexpected error with message Cannot insert into out of bounds index #4903 cut specs,clipboardandstability._electronwith real mouse, keyboard and menu clicks): the table above, onbuild:unpackbuilds ofdevelopand of this branch, both with fix(muya): don't drop blocks when a cut ends inside a code block (#4903, #5148) #5357 reverted, plus the packaged 0.20.0-rc.2.vitest runpasses 235 files / 1666 tests;lint:types, eslint on the changed files andcheck-circularpass.Notes for reviewers
Outro paragraphin the steps above).flush()callers (save, tab switch, entering source mode) still get the rethrown error, as before. The document is already consistent by then, so trying again works.By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.
🤖 Generated with Claude Code
https://claude.ai/code/session_01WEPLCvFTgbYf35z85XUJop