Fix overlapping search highlights for adjacent multi-word matches#4415
Draft
zenoachtig wants to merge 2 commits into
Draft
Fix overlapping search highlights for adjacent multi-word matches#4415zenoachtig wants to merge 2 commits into
zenoachtig wants to merge 2 commits into
Conversation
Multi-word search queries highlight each word independently, so a phrase like "maria db" against "MariaDB" produced two touching highlight spans whose negative margins and rounded corners overlapped into a doubled pill. Coalesce contiguous matched parts into a single highlight span. The pure matching logic is extracted to HighlightQuery.utils.ts so it can be unit-tested without pulling in the React JSX runtime. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H4jiy83BeKXZjEH4Jqwn3Z
🦋 Changeset detectedLatest commit: d55764e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
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.
Night-shift draft — not ready to merge; prepared for Zeno to review in the morning.
Source: #published-docs-experience Slack thread where Nolann reported that searching
maria db cloudrenders MariaDB as two overlapping highlight pills (whilemariadb cloudlooks fine). Zeno diagnosed the cause in-thread; this implements that fix.Overview
HighlightQueryhighlights each query word independently (matchStringreduces the text word-by-word). A multi-word query whose words are contiguous in the result text — e.g.maria dbinsideMariaDB— produced two touching<span>matches. Because each highlight span carries-mx-0.5(negative margin) androunded-sm, adjacent spans overlap into a visually doubled/seamed pill.coalesceAdjacentMatches). Non-adjacent matches (unmatched text between them) still render as separate highlights.HighlightQuery.utils.tsso it can be unit-tested without pulling in the React JSX runtime (mirrors the existingfilter.ts/filter.test.tssplit).HighlightQuery.tsxnow just importsmatchStringand renders.Test
packages/gitbook/src/components/Search/HighlightQuery.utils.test.ts(bun test) — covers no-match, single-word match, the adjacent-coalesce regression (maria db cloud→ oneMariaDBpill + oneCloudpill), and non-adjacent matches staying separate. The coalesce case fails onmainand passes with this change. All 4 pass locally.For Zeno
maria cloudagainstMariaDB is a cloud databasestill yields two separate pills, which is correct. Merged span'smatchvalue is the concatenation of the matched tokens; it's only used as a truthy styling flag, so the exact value doesn't matter downstream.HighlightQuery.utils.ts. If you'd rather keep it inline in the.tsx, the test can instead import through the component — but then it needs the JSX runtime and doesn't run underbun testcleanly. Happy to fold it back if you prefer.@gitbook/icons,@gitbook/embed, …) in the fresh container — no errors in the changed files. CI will confirm.Changelog
Generated by Claude Code