Skip to content

fix(document-view): bound Find highlights and navigation - #1063

Merged
dovvnloading merged 1 commit into
mainfrom
agent/bound-document-find-highlights
Nov 25, 2026
Merged

dovvnloading merged 1 commit into
mainfrom
agent/bound-document-find-highlights

Conversation

@dovvnloading

Copy link
Copy Markdown
Owner

Summary

Fixes #1051. A frequent Find query could spread hundreds of thousands of replacement nodes into one splice call and crash Document View. Build each changed sibling array once, cap rendered matches at 1,000 in document order, and retain all original document text. The search bar explicitly labels the highlight limit rather than presenting it as the exhaustive number of occurrences.

What Changed

  • Preserve existing literal case-insensitive and whitespace-aware matching, inline-element boundaries, decorative heading-link exclusion, and stable match indices. Stop searching once the cap is reached.
  • Defer the expensive Markdown render with React's deferred value (not a fixed-duration debounce). Keep the input urgent, show a pending status and disable navigation while it settles; clearing Find removes highlights immediately.
  • Memoize the lazy Markdown renderer and cache the bounded rendered match list; next/previous updates only the previous and current marks. Handle initial lazy-render arrival without losing the match count.
  • Add three AST regressions, two search-bar regressions, and a panel regression covering cap, complete source text, wraparound, and resetting the query.

Why

The number of added highlight nodes is bounded regardless of document size or frequency of the query. A 1,000-highlight ceiling is an intentional product tradeoff: later occurrences remain ordinary text; refine the query to find them. Search is still limited to individual HAST text nodes. The count explicitly says (limit) at the ceiling (including exactly 1,000 matches, since the scan stops there). No change to stored content or citation offsets.

Validation

  • Reproduced the original unbounded spread failure in Node 22 (300,000 arguments).
  • Strict TypeScript compilation of the isolated highlighter and 7 Node assertions/checks passed, including the reproduction, 300,000-match input, intact text, cap across nested elements, depth-first indices, literal/whitespace matching, decorative nodes, unchanged unmatched nodes and reset. The tested transform body matches the committed source.
  • Reviewed the committed diff: six intended files, one commit ahead of main and zero behind at comparison time.
  • App launches
  • Relevant workflow was exercised manually
  • python -m compileall -q . passes (run from the repo root - matches CI)
  • python -m pytest -q passes (run from the repo root - matches CI)
  • cd web_ui && npm run check passes (matches CI)

Local checkout is blocked by GitHub DNS resolution. The isolated checks do not run React, React Markdown, Vitest, the full TypeScript project, lint or the application. The new component tests and all required CI checks remain to be run. From a configured checkout:

npm --prefix web_ui run test -- src/app/canvas/documentViewSearchHighlight.test.ts src/app/canvas/DocumentViewSearch.test.tsx src/app/canvas/DocumentViewPanel.test.tsx
npm --prefix web_ui run check

Manual verification: open a long Markdown document with many occurrences of a common character; type and refine the query; verify the limit label, intact document, wraparound, keyboard navigation, clearing search and both themes. No browser latency or memory benchmark has been run.

UI Notes

  • Screenshots included if the change is visual
  • No screenshots needed

Visible status text changes, but there are no styling changes. Dark/light and narrow-panel visual checks remain pending.

Additional Context

No dependency, schema, CI, or unrelated changes. Draft pending CI and manual verification; do not merge until these pass.

@dovvnloading dovvnloading left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all six changed files against #1051. The shared 1,000-match limit and sibling-array reconstruction remove the unbounded splice while retaining the unmarked tail; navigation caches the rendered marks and the search bar communicates both deferred results and the cap. The literal/whitespace semantics, decorative anchor exclusion, document order, and citation pipeline remain intact.

CI run 2341 succeeded: Python compile/pytest, POSIX permissions, wheel installation/build, and frontend schema/typecheck/lint/Vitest/build. The frontend log confirms 51 DocumentViewPanel, 14 DocumentViewSearch, and 16 highlighter tests passed (4,173 total). Main has advanced since this head; I inspected the intervening DocumentViewMarkdown citation changes for compatibility. No blocking source-review findings.

Limitations: Playwright boot-smoke was skipped by CI, and a separate manual desktop/browser run, visual checks in both themes, and latency measurement could not be performed because the local checkout is blocked by DNS. This is a maintainer-delegated review comment, not an independent GitHub approval.

@dovvnloading
dovvnloading marked this pull request as ready for review November 25, 2026 10:55
@dovvnloading
dovvnloading merged commit d0b8f89 into main Nov 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(document-view): high-frequency Find queries can exceed the JavaScript argument limit and crash rendering

1 participant