Skip to content

fix(muya): skip search matches whose block left the document (#5163, #5215) - #5287

Merged
Jocs merged 3 commits into
developfrom
fix/5163-search-stale-match
Sep 10, 2026
Merged

Jocs merged 3 commits into
developfrom
fix/5163-search-stale-match

Conversation

@Jocs

@Jocs Jocs commented Sep 10, 2026

Copy link
Copy Markdown
Member

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.:

Search stores 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 calls muya.search('', { selectHighlight: true }), which puts the cursor back on the previous active match. That block is no longer in the document, so setCursor cannot 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, Chromium (e2e/tests/editing/search-stale-match-5163.spec.ts): search foo in # 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.
  • Unit (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 files

e2e/tests/editing/search-replace.spec.ts (#single / #all) also fails locally on unmodified develop for 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

Jocs and others added 3 commits September 10, 2026 19:58
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
@Jocs
Jocs merged commit d7cda0d into develop Sep 10, 2026
7 checks passed
@Jocs
Jocs deleted the fix/5163-search-stale-match branch September 10, 2026 13:58
@Jocs Jocs mentioned this pull request Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant