Repository navigation
fix(muya): skip identity operations during deferred flush - #4815
Merged
Merged
Conversation
ot-json1.compose() may legitimately return the identity operation (null) when queued operations cancel each other out, such as during IME composition. JSONState._flushOperationCache() assumed that any non-empty operation batch would compose to a non-null operation and emitted it through the json-change event. Downstream consumers such as History expected a JSONOpList and crashed when receiving null. Skip emitting json-change for identity operations to preserve the ot-json1 contract and avoid forwarding no-op operations.
tech-hoon
marked this pull request as ready for review
July 2, 2026 03:38
Jocs
approved these changes
Jul 4, 2026
3 tasks done
Jocs
added a commit
that referenced
this pull request
Jul 4, 2026
) * fix(muya): tolerate identity (null) json-change ops in History `ot-json1.compose()` legitimately returns the identity operation (`null`) when queued operations cancel each other out (for example during IME composition). PR #4815 stopped the deferred-flush emitter from forwarding that null, but `dispatch()` — used by `Editor.updateContents` and `rebuildContents` — still forwards it deliberately, and the `updateContents` contract explicitly routes the no-op through `json-change`. `History`'s `json-change` listener passed the op straight to `_record` (and `_transform`), both of which read `op.length` and crash on `null` with `TypeError: Cannot read properties of null (reading 'length')`. Ignore identity ops in the listener: a no-op has nothing to record or transform. This closes the crash at the consumer regardless of which emitter produced the null. Refs #4806 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * test(muya): cover identity-op json-change crash (#4806) Two regressions for the null-op crash: - `updateContents(null)` drives the `dispatch` path that forwards the identity op through `json-change`; asserts History neither crashes nor records an undo entry. - Flushing a compose-to-null batch (an op and its exact inverse) asserts the deferred-flush emitter stays silent, locking the PR #4815 fix. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
This was referenced Jul 4, 2026
Closed
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.
Fixes #4806
Summary
Fix a crash caused by forwarding identity JSON operations (
null) emitted byot-json1.compose().During deferred operation flushing, queued operations may cancel each other out (for example during IME composition), causing
compose()to legitimately returnnull.JSONState._flushOperationCache()forwarded this identity operation through thejson-changeevent, while downstream consumers such asHistoryexpected aJSONOpList, resulting in:This change skips emitting
json-changeevents for identity operations.Type of change
Test plan
Manual verification
Demo
The attached recording reproduces the crash.
2026-07-02.9.25.40.mov
Notes for reviewers
ot-json1.type.compose()returnsJSONOp(null | JSONOpList), wherenullrepresents the identity operation.This change preserves the
ot-json1contract by preventing identityoperations from being forwarded through the
json-changeevent.