Repository navigation
fix(muya): harden History against identity (null) json-change ops - #4838
Merged
Merged
Conversation
`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]>
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]>
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.
Refs #4806. Follow-up hardening for #4815.
Summary
ot-json1.compose()legitimately returns the identity operation (null)when queued operations cancel each other out — for example during IME
composition, where an insert and a delete land in the same animation frame.
#4815 fixed the reported crash by stopping the deferred-flush emitter
(
JSONState._flushOperationCache) from forwarding thatnullthroughjson-change. This PR closes the same crash at the consumer, coveringthe remaining emitter that #4815 did not touch.
Why a second fix
JSONState.dispatch()— used byEditor.updateContentsandEditor.rebuildContents— still forwards the identity op deliberately. TheupdateContentscontract even documents this ("the ot-json1 no-op isforwarded to dispatch … so listeners still see a json-change event for the
no-op"). But
History'sjson-changelistener handed the op straight to_record/_transform, both of which readop.length:Today that path only fires under History's own
_ignoreChangeguard (undo/redo,
replaceContent), so it does not crash in production — but it is alatent trap: any future caller invoking
updateContents(null)outside thatguard reproduces the identical crash via a different stack.
Change
Ignore identity ops in History's
json-changelistener — a no-op hasnothing to record or transform. This makes History crash-proof against a
nullop regardless of which emitter produced it, and leavesdispatch'sexisting "forward the no-op" contract intact.
Test plan
packages/muyaunit tests — newidentityOpJsonChange.spec.ts:updateContents(null)no longer crashes History and records no undo entry (fails without this fix).history+statesuites green (222 tests).lint+lint:typesclean.🤖 Generated with Claude Code