Repository navigation
fix(muya): guard checkNeedRender against a null cursor (image-preview reclick crash) - #4588
Merged
Merged
Conversation
Format.checkNeedRender resolved its offsets via `anchor!.offset` / `focus!.offset`, but blurHandler() calls it with the default cursor built from this.selection.anchor/focus. After the image-preview path (select image -> Space opens SimpleImageViewer -> Esc), ImageSelection never seats a text caret, so the image's paragraph stays the active content block with a null selection. The next click fires blurHandler() on that paragraph and the undefined offsets threw "Cannot read properties of undefined (reading 'offset')". Return false (nothing to re-render) when no cursor offset is resolvable. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Jocs
force-pushed
the
fix/image-preview-blur-crash
branch
from
June 20, 2026 07:46
2c4af81 to
dd333a9
Compare
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 a renderer crash when clicking an inline image again after closing its full-screen preview.
Repro: select an inline image → press Space (opens
SimpleImageViewer) → press Esc → click the same image again →TypeError: Cannot read properties of undefined (reading 'offset').Root cause:
Format.checkNeedRender(packages/muya/src/block/base/format.ts) resolved its anchor/focus offsets with non-null assertions (anchor!.offset/focus!.offset).blurHandler()invokes it with the default cursor derived fromthis.selection.anchor/focus. The image-preview path leaves the image's paragraph as the active content block with a null selection (no text caret is seated, and Esc doesn't restore one), so the next click'sblurHandler()dereferencedundefined.offset.Fix: when no cursor offset is resolvable there is nothing for the cursor-proximity check to compare against, so return
false(no re-render needed) instead of dereferencing.Test
Adds
packages/muya/src/block/base/__tests__/blurHandlerNullCursor.spec.ts(TDD — written failing first):blurHandler()/checkNeedRender()no longer throw with a null selection and returnfalse, while a real cursor inside inline markup still triggers a re-render.Verification
🤖 Generated with Claude Code