Repository navigation
fix(muya): guard detached code block in language selector (#4654) - #4677
Merged
Merged
Conversation
Jocs
force-pushed
the
fix/codeblock-lang-selector-null-parent
branch
from
June 24, 2026 12:40
0b90f59 to
f5ef557
Compare
Selecting a language from the code-block language picker crashed the renderer when the picker's target block had been detached from the document while the picker stayed open (e.g. the code block was converted back to a paragraph via Backspace at offset 0 of the code body, orphaning its language-input child). `selectItem`'s `block.text = name` runs the Content text setter, which re-computes an OT path for the edit operation. For a language-input that path walks up to its code block, whose `path` getter dereferences its own (now null) parent — throwing `Cannot destructure property 'path' of 'this.parent'`. The retired muyajs engine hit the same class at `ContentState.updateCodeLanguage` (`reading 'functionType'` of null). Bail out of `selectItem` when `block.outMostBlock` is null — the block (or any ancestor) is no longer connected to the document root — before mutating its text/lang. `outMostBlock` walks the full parent chain, so it catches the detached-grandparent case a shallow `block.parent` check misses. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Drives the real CodeBlockLanguageSelector float in Chromium: opens the picker on a code block nested in a list, detaches the block, then clicks a language item and asserts no uncaught renderer pageerror. Fails on the pre-fix engine with `Cannot destructure property 'path' of 'this.parent'`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The language picker only hid on a non-matching query or a document click, so moving the caret out of the language input (e.g. Left/Right arrow) left it open over a stale target. Subscribe to `selection-change` and hide the picker when the caret's anchorBlock is no longer its target block — the same self-perceiving pattern InlineFormatToolbar uses. This also closes the window that let the target block be detached from under the picker (#4654); the selectItem outMostBlock guard remains as defense in depth. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Jocs
force-pushed
the
fix/codeblock-lang-selector-null-parent
branch
from
June 24, 2026 14:50
f5ef557 to
e43c0d0
Compare
Member
Author
|
Added a third commit: The picker now subscribes to |
This was referenced Sep 10, 2026
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
Fixes #4654 (renderer crash when selecting a language for a code block).
When the language picker is open and its target code block is detached from
the document — e.g. the code block is converted back to a paragraph via
Backspace at offset 0 of the code body, orphaning its
language-inputchild —selecting a language crashes the renderer.
selectItem's first mutation,block.text = name, runs theContenttextsetter, which re-computes an OT path for the edit. For a
language-inputthatpath walks up to its code block, whose
pathgetter dereferences its own (nownull) parent:On the retired
muyajsengine the same class surfaced asCannot read properties of null (reading 'functionType')atContentState.updateCodeLanguage.Fix
Bail out of
selectItemwhenblock.outMostBlockisnull— the block (or anyancestor) is no longer connected to the document root — before mutating its
text/lang.
outMostBlockwalks the full parent chain, so it catches thedetached-grandparent case (the language-input's immediate parent still exists,
but the code block above it is detached) that a shallow
block.parentcheckmisses.
Tests
muya-e2e) —code-block-language-selector-orphan-4654.spec.tsdrives the real picker float in Chromium: opens it on a code block nested in a
list, detaches the block via the actual
codeBlockContent.backspaceHandler,clicks a language item, and asserts no uncaught
pageerror. This is theauthoritative reproduction — it fails on the pre-fix engine with the
path-destructure crash and passes with the guard.selectItem.spec.tspins the guard contract (a detached block,outMostBlocknull, is left untouched) and the attached happy path.Note
The first revision of this PR guarded the wrong line (
block.parent.lang).End-to-end verification in the real engine showed the crash actually fires one
statement earlier, at
block.text = name, and one ancestor level up(immediate parent present, code block detached) — so the fix was reworked to
the
outMostBlockguard above and backed by the e2e reproduction.🤖 Generated with Claude Code