Skip to content

fix(preset-algolia): keep separator highlight when reverse-highlight siblings disagree#1348

Open
devteamaegis wants to merge 1 commit into
algolia:nextfrom
devteamaegis:fix/reverse-highlight-sibling-state
Open

fix(preset-algolia): keep separator highlight when reverse-highlight siblings disagree#1348
devteamaegis wants to merge 1 commit into
algolia:nextfrom
devteamaegis:fix/reverse-highlight-sibling-state

Conversation

@devteamaegis

Copy link
Copy Markdown

What's broken

In the reverse-highlight / reverse-snippet "sibling strategy", isPartHighlighted computes neighbor state with ||:

const isNextHighlighted = parts[i + 1]?.isHighlighted || true;
const isPreviousHighlighted = parts[i - 1]?.isHighlighted || true;

X || true is always true, even when the neighbor exists and is genuinely false. So the isPreviousHighlighted === isNextHighlighted guard is always true, and every separator part between mismatched neighbors is wrongly treated as highlighted-from-siblings. For a value where a separator sits between a highlighted and a non-highlighted segment, the reverse-highlight output is wrong.

Why it happens

|| was used where a "default only when the neighbor is missing" was intended — the ?. optional chaining shows the intent. false || true collapses a real false neighbor to true.

Fix

Use ?? so the true default applies only when the neighbor is absent (undefined).

Test

Added a case: a separator between a highlighted and a non-highlighted segment keeps its own state; fails before, passes after. Full autocomplete-preset-algolia suite stays green.

…siblings disagree

isPartHighlighted defaulted neighbor highlight states with `|| true`, which
also overrode an existing `false` neighbor. That made both siblings always
appear highlighted, so every non-alphanumeric separator was treated as
highlighted-from-siblings regardless of its real neighbors. Use `?? true` so
the default only applies when a neighbor is missing.
@codacy-production

codacy-production Bot commented Jun 11, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

TIP This summary will be updated as you push new changes.

@devteamaegis devteamaegis force-pushed the fix/reverse-highlight-sibling-state branch from 7e6df5f to 3837461 Compare June 11, 2026 19:44
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.

1 participant