Skip to content

fix(autocomplete-preset-algolia): support Unicode in ReverseHighlight#1330

Merged
Haroenv merged 2 commits intoalgolia:fix/unicode-highlightingfrom
rinoshiyo:fix/preset-algolia-unicode-reverse-highlight
Jan 28, 2026
Merged

fix(autocomplete-preset-algolia): support Unicode in ReverseHighlight#1330
Haroenv merged 2 commits intoalgolia:fix/unicode-highlightingfrom
rinoshiyo:fix/preset-algolia-unicode-reverse-highlight

Conversation

@rinoshiyo
Copy link
Copy Markdown
Contributor

@rinoshiyo rinoshiyo commented Jan 27, 2026

Summary

This PR fixes ReverseHighlight behavior for non-ASCII queries (e.g., Japanese and Cyrillic) in @algolia/autocomplete-preset-algolia.

isPartHighlighted previously used an ASCII-only \w check to detect "word characters". In JavaScript, \w matches [A-Za-z0-9_] and does not match Unicode letters. As a result, Unicode text could be treated as a "separator" by the normalization logic, which could lead to incorrect ReverseHighlight output (see #1317).

This change replaces the ASCII-only check with a Unicode-aware check (Unicode property escapes) and renames the variable accordingly. A fallback to the previous \w behavior is kept for environments where Unicode property escapes are unavailable.

Result

npm test -- --testPathPattern=isPartHighlighted\.test\.ts

Output:

 PASS  packages/autocomplete-preset-algolia/src/highlight/__tests__/isPartHighlighted.test.ts
  isPartHighlighted
    ✓ returns the isHighlighted value with a missing sibling (1 ms)
    ✓ returns the isHighlighted value with both siblings (1 ms)
    ✓ does not treat Japanese text as a separator at the start (俺はジャイアン)
    ✓ does not treat Japanese text as a separator in the middle (俺はジャイアンだ)
    ✓ does not treat Japanese text as a separator at the end (俺はジャイアンだ)
    ✓ does not treat Cyrillic text as a separator at the start (regression #1317)
    ✓ does not treat Cyrillic text as a separator in the middle (regression #1317)
    ✓ does not treat Cyrillic text as a separator at the end (regression #1317)

Test Suites: 1 passed, 1 total
Tests:       8 passed, 8 total
Snapshots:   0 total
Time:        0.493 s, estimated 1 s

fixes #1317

UI Evidence (Before / After)

Before (current behavior)

  • Query: 音声
  • ReverseHighlight does not highlight the non-matching suffix part as expected.
image

After (this PR)

  • Query: 音声
  • ReverseHighlight highlights the non-matching suffix (e.g., "dl book") while keeping the matching prefix unhighlighted.
image

@codesandbox-ci
Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 29fe8c4:

Sandbox Source
@algolia/autocomplete-example-github-repositories-custom-plugin Configuration
@algolia/autocomplete-example-instantsearch Configuration
@algolia/autocomplete-example-playground Configuration
@algolia/autocomplete-example-preview-panel-in-modal Configuration
@algolia/autocomplete-example-starter-algolia Configuration
@algolia/autocomplete-example-starter Configuration
@algolia/autocomplete-example-reshape Configuration
@algolia/autocomplete-example-vue Configuration

@Haroenv Haroenv changed the base branch from next to fix/unicode-highlighting January 28, 2026 08:19
@Haroenv Haroenv self-requested a review January 28, 2026 08:20
Copy link
Copy Markdown
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

thanks, this looks great, and still safe for older browsers

@Haroenv Haroenv merged commit 53347ed into algolia:fix/unicode-highlighting Jan 28, 2026
2 checks passed
@Haroenv
Copy link
Copy Markdown
Contributor

Haroenv commented Jan 28, 2026

moved to #1331 so that CI can run

Haroenv added a commit that referenced this pull request Feb 2, 2026
…#1330) (#1331)

* fix(autocomplete-preset-algolia): support Unicode word characters in ReverseHighlight

* test(autocomplete-preset-algolia): add regression tests for Unicode ReverseHighlight

fixes #1317

see #1330

Co-authored-by: rinoshiyo <45587676+rinoshiyo@users.noreply.github.com>
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.

ReverseHighlight does not highlight Cyrillic characters correctly

2 participants