[PR #3528] [MERGED] feat(docs): highlight search terms in the in-app docs viewer #5981

Closed
opened 2026-10-23 04:05:52 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3528
Author: @kolacheee
Created: 7/12/2026
Status: ✅ Merged
Merged: 7/12/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/docs-search-highlight


📝 Commits (6)

  • 42450d0 feat(docs): highlight search terms in the docs viewer
  • 88bf5d4 docs: changelog entry for docs-viewer search highlighting
  • 8006403 fix(docs): harden search highlighting against reconcile and Unicode edge cases
  • 6ef6ed2 Merge branch 'staging' into feat/docs-search-highlight
  • 02d9c39 Merge remote-tracking branch 'origin/staging' into feat/docs-search-highlight
  • 9148661 Address docs search review feedback

📊 Changes

3 files changed (+177 additions, -11 deletions)

View changed files

📝 CHANGELOG.md (+6 -0)
📝 packages/client/src/components/modals/DocsViewerModal.tsx (+159 -11)
📝 packages/client/src/styles/globals.css (+12 -0)

📄 Description

Linked issue

No filed issue — this is a direct UX request from the contributor's own use of the docs viewer (searching the guides gives match counts and snippets, but nothing shows where the matches are once a guide is open). Happy to open a tracking issue if maintainers prefer one on record.

Why this change

The in-app docs viewer's search tells you that a guide matches (count badge, snippet lines) but not where — opening a result scrolls near the first occurrence and then you're on your own, scanning paragraphs for the word you typed. This highlights the search term everywhere it appears so users can actually see what they searched for.

What changed

  • In the opened guide: while a search is active (debounced query ≥ 2 chars), every occurrence of the query is wrapped in a highlight mark — live as you type, cleared when the search clears, capped at 500 marks per doc. Opening a guide from a search result scrolls to the first highlighted match (with the old raw-text walk as fallback).
  • In the sidebar: result titles and snippet lines highlight the matched term (pure React, covers the title-only-match case where a result shows with no snippets).
  • Matching mirrors the server exactly: literal, case-insensitive, whole-query substring via toLowerCase() + indexOf — never a regex — so highlights agree with the server's match counts, and metacharacter queries (c++, a|b) match literally. The needle is capped at 200 chars like the server's.
  • Implementation keeps the chat-shared markdown renderer untouched: the doc-body highlighting augments the committed DOM in an effect, exactly like the existing Copy-button pattern in the same file (walk-then-mutate so the TreeWalker is never invalidated; cleanup unwraps precisely the marks it created and re-normalizes text nodes; Copy-button text is excluded from wrapping).
  • Hardening from review: (1) the rendered-markdown container is now keyed on the rendered tree's identity — useDocContent keeps the previous doc as placeholderData, so the tree could change identity without a selected change, and React would reconcile against effect-mutated DOM (stale text or an insertBefore crash); the key forces a clean remount instead. This also hardens the pre-existing Copy-button augmentation. (2) Text where toLowerCase() changes string length (e.g. İ → i + U+0307) is skipped rather than highlighted at misaligned offsets.
  • Styling: one plain CSS class (.docs-search-mark) next to the existing .mari-md-highlight rule — primary-tinted via color-mix, readable in both themes, visually distinct from markdown ==highlight== yellow, and self-scoping (nothing outside the docs viewer emits it).

Files: packages/client/src/components/modals/DocsViewerModal.tsx, packages/client/src/styles/globals.css, CHANGELOG.md. Client-only; no server or shared-package changes.

Review process

Built and reviewed with a tiered multi-agent pipeline: recon scanners mapped the search backend semantics, renderer internals, styling conventions, and regression surface; a synthesis pass produced the design; four adversarial reviewers (DOM lifecycle, regressions, hostile inputs, perf/a11y) generated findings that were each independently double-verified — 1 confirmed (the Unicode offset case, fixed), 2 refuted with reproducible reasoning (a needle-cap mismatch that is provably a no-op since server snippets are ≤160 chars, and a misapplied WCAG 1.4.11 claim). The placeholderData reconcile hazard was caught in a final manual pass and fixed.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Automated on the dev machine: pnpm lint clean (shared + server + client typechecks + eslint); client production build clean. (pnpm check's full build step remains blocked on this Windows dev machine by the pre-existing #3162 build-script bug; the typechecks it wraps pass.)

To verify in a real browser before merge:

  • Open the docs viewer, type a ≥2-char query with a guide open → occurrences highlight live; clearing the search (X or emptying) removes every highlight; keep typing → highlights follow the debounced query.
  • Click a search result → the guide opens scrolled to the first highlighted match, sidebar title/snippets show the term highlighted.
  • Matches inside code blocks highlight, the Copy button never does, and Copy still copies the full code text.
  • Switch guides mid-search (including an uncached guide, and re-clicking the already-open guide) → no stale marks, no console errors, correct highlights on the new guide.
  • Cross-doc links inside guides still navigate in-modal (including a link whose text contains a highlighted term).
  • Reading-position restore still works: close the viewer mid-guide, reopen → same scroll position.
  • Light + dark themes both legible; mobile: tap a result → highlights visible in the reader; Back returns to the list.
  • Chat regression spot-check: chat messages with markdown render unchanged (the shared renderer is untouched, but confirm visually).

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

Docs touched: CHANGELOG.md (entry under a new [Unreleased] section). No version bump.

UI evidence (if applicable)

Screenshots pending the manual verification pass.

Summary by CodeRabbit

  • New Features
    • Documentation search now highlights every matching term in the open guide.
    • Matching terms are highlighted in guide titles and result snippets.
    • Selecting a search result automatically scrolls to the first matching occurrence.
    • Added styling for clearer, more readable search highlights.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/3528 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 7/12/2026 **Status:** ✅ Merged **Merged:** 7/12/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/docs-search-highlight` --- ### 📝 Commits (6) - [`42450d0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/42450d010fbb2e06abbfd65d8a3a0d8b2caf6c7c) feat(docs): highlight search terms in the docs viewer - [`88bf5d4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/88bf5d4a2036cbbe932859638a38b52b28e38b6b) docs: changelog entry for docs-viewer search highlighting - [`8006403`](https://github.com/Pasta-Devs/Marinara-Engine/commit/80064039bad0b7c5275eab62eedb963c825213bd) fix(docs): harden search highlighting against reconcile and Unicode edge cases - [`6ef6ed2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6ef6ed2e52c0927efe61e974724b4ccdcaf37299) Merge branch 'staging' into feat/docs-search-highlight - [`02d9c39`](https://github.com/Pasta-Devs/Marinara-Engine/commit/02d9c39fdcc85bb33d3fb6fea3c2404789b5d657) Merge remote-tracking branch 'origin/staging' into feat/docs-search-highlight - [`9148661`](https://github.com/Pasta-Devs/Marinara-Engine/commit/91486613f925cd117ecbcccae305e9abcd624f58) Address docs search review feedback ### 📊 Changes **3 files changed** (+177 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+6 -0) 📝 `packages/client/src/components/modals/DocsViewerModal.tsx` (+159 -11) 📝 `packages/client/src/styles/globals.css` (+12 -0) </details> ### 📄 Description ## Linked issue No filed issue — this is a direct UX request from the contributor's own use of the docs viewer (searching the guides gives match counts and snippets, but nothing shows *where* the matches are once a guide is open). Happy to open a tracking issue if maintainers prefer one on record. ## Why this change The in-app docs viewer's search tells you *that* a guide matches (count badge, snippet lines) but not *where* — opening a result scrolls near the first occurrence and then you're on your own, scanning paragraphs for the word you typed. This highlights the search term everywhere it appears so users can actually see what they searched for. ## What changed - **In the opened guide:** while a search is active (debounced query ≥ 2 chars), every occurrence of the query is wrapped in a highlight mark — live as you type, cleared when the search clears, capped at 500 marks per doc. Opening a guide from a search result scrolls to the first highlighted match (with the old raw-text walk as fallback). - **In the sidebar:** result titles and snippet lines highlight the matched term (pure React, covers the title-only-match case where a result shows with no snippets). - **Matching mirrors the server exactly:** literal, case-insensitive, whole-query substring via `toLowerCase()` + `indexOf` — never a regex — so highlights agree with the server's match counts, and metacharacter queries (`c++`, `a|b`) match literally. The needle is capped at 200 chars like the server's. - **Implementation keeps the chat-shared markdown renderer untouched:** the doc-body highlighting augments the committed DOM in an effect, exactly like the existing Copy-button pattern in the same file (walk-then-mutate so the TreeWalker is never invalidated; cleanup unwraps precisely the marks it created and re-normalizes text nodes; Copy-button text is excluded from wrapping). - **Hardening from review:** (1) the rendered-markdown container is now keyed on the rendered tree's identity — `useDocContent` keeps the previous doc as `placeholderData`, so the tree could change identity *without* a `selected` change, and React would reconcile against effect-mutated DOM (stale text or an `insertBefore` crash); the key forces a clean remount instead. This also hardens the pre-existing Copy-button augmentation. (2) Text where `toLowerCase()` changes string length (e.g. `İ` → `i` + U+0307) is skipped rather than highlighted at misaligned offsets. - **Styling:** one plain CSS class (`.docs-search-mark`) next to the existing `.mari-md-highlight` rule — primary-tinted via `color-mix`, readable in both themes, visually distinct from markdown `==highlight==` yellow, and self-scoping (nothing outside the docs viewer emits it). Files: `packages/client/src/components/modals/DocsViewerModal.tsx`, `packages/client/src/styles/globals.css`, `CHANGELOG.md`. Client-only; no server or shared-package changes. ### Review process Built and reviewed with a tiered multi-agent pipeline: recon scanners mapped the search backend semantics, renderer internals, styling conventions, and regression surface; a synthesis pass produced the design; four adversarial reviewers (DOM lifecycle, regressions, hostile inputs, perf/a11y) generated findings that were each independently double-verified — 1 confirmed (the Unicode offset case, fixed), 2 refuted with reproducible reasoning (a needle-cap mismatch that is provably a no-op since server snippets are ≤160 chars, and a misapplied WCAG 1.4.11 claim). The placeholderData reconcile hazard was caught in a final manual pass and fixed. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes Automated on the dev machine: `pnpm lint` clean (shared + server + client typechecks + eslint); client production build clean. (`pnpm check`'s full build step remains blocked on this Windows dev machine by the pre-existing #3162 build-script bug; the typechecks it wraps pass.) To verify in a real browser before merge: - Open the docs viewer, type a ≥2-char query with a guide open → occurrences highlight live; clearing the search (X or emptying) removes every highlight; keep typing → highlights follow the debounced query. - Click a search result → the guide opens scrolled to the first highlighted match, sidebar title/snippets show the term highlighted. - Matches inside code blocks highlight, the Copy button never does, and Copy still copies the full code text. - Switch guides mid-search (including an uncached guide, and re-clicking the already-open guide) → no stale marks, no console errors, correct highlights on the new guide. - Cross-doc links inside guides still navigate in-modal (including a link whose text contains a highlighted term). - Reading-position restore still works: close the viewer mid-guide, reopen → same scroll position. - Light + dark themes both legible; mobile: tap a result → highlights visible in the reader; Back returns to the list. - Chat regression spot-check: chat messages with markdown render unchanged (the shared renderer is untouched, but confirm visually). ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) Docs touched: `CHANGELOG.md` (entry under a new `[Unreleased]` section). No version bump. ## UI evidence (if applicable) _Screenshots pending the manual verification pass._ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Documentation search now highlights every matching term in the open guide. * Matching terms are highlighted in guide titles and result snippets. * Selecting a search result automatically scrolls to the first matching occurrence. * Added styling for clearer, more readable search highlights. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:05:52 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#5981
No description provided.