Repository navigation
fix(muya): skip search matches whose block left the document (#5163, #5215) - #5287
Merged
Merged
Conversation
Search keeps live block references in its matches. When an edit replaces
the matched block (a heading turned into a paragraph, for example),
closing the find bar calls `search('', { selectHighlight: true })`, which
put the cursor back on the previous active match. Its block was no longer
in the document, so `setCursor` failed to resolve the block path and
threw "Cannot destructure property 'path' of 'this.parent' as it is null".
Only restore the cursor onto a match whose block is still attached, and
skip detached blocks when clearing or repainting highlights.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015EPgRzXj7DDhJToWxHtkkR
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015EPgRzXj7DDhJToWxHtkkR
…graph (#5163) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015EPgRzXj7DDhJToWxHtkkR
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.
Summary
Fixes #5163
Fixes #5215
Both crash reports (v0.20.0-rc.1) show
TypeError: Cannot destructure property 'path' of 'this.parent' as it is null.:AtxHeadingContent.setCursor←Search.search←emptySearchCodeBlockContent.setCursor←Search.searchSearchstores live block references in its matches. When an edit replaces the matched block while the find bar is open (a heading turned into a paragraph, or a code block rebuilt), the matches still point at the old block. Closing the find bar callsmuya.search('', { selectHighlight: true }), which puts the cursor back on the previous active match. That block is no longer in the document, sosetCursorcannot resolve its path and throws.The fix only restores the cursor onto a match whose block is still attached (
block.outMostBlock), and skips detached blocks when clearing or repainting highlights.Test plan
e2e/tests/editing/search-stale-match-5163.spec.ts): searchfooin# foo, press Backspace at the heading start, close the search the way the desktop find bar does, then keep typing. Before the fix: the TypeError above.src/search/__tests__/searchStaleMatch.spec.ts): closing a search whose active match was detached does not throw. Before the fix: the same TypeError.pnpm -C packages/muya test(1476 passed),pnpm -C packages/muya lint:types, eslint on the changed filese2e/tests/editing/search-replace.spec.ts(#single/#all) also fails locally on unmodifieddevelopfor me: it reads markdown before the next animation frame flushes the edit. That spec is unchanged here and passes in CI.🤖 Generated with Claude Code
https://claude.ai/code/session_015EPgRzXj7DDhJToWxHtkkR