Skip to content

[Bug] PowerSearch: Enter during IME composition splits the last character into a separate filter #4828

Closed

Description

@yomybaby

Description

Typing with an IME (Korean / Japanese / Chinese) in PowerSearch's free-text content search field and pressing Enter to commit the composition is misinterpreted as "accept the highlighted suggestion". The pending syllable is then re-committed into the freshly-cleared input, so the last character the user was still composing ends up as its own separate filter chip.

Expected: the first Enter only commits the IME composition (no filter is created). A second Enter then creates one filter containing the whole phrase.

Actual: one Enter creates a filter and leaves the trailing syllable behind in the input, which becomes a second, spurious single-character filter.

This is the same class of bug already fixed for overlays and the chat composer in #3357 / #4280 — BaseTypeahead just never got the guard, so everything built on it (PowerSearch, Tokenizer, Typeahead) is still affected.

Reproduction

Hosted Storybook: core-powersearch — With Content Search Field Key

  1. Switch the OS input source to a Korean IME (2-Set / 두벌식).
  2. Click the PowerSearch input (Type to search by title, or pick a field...).
  3. Type 한국어. The trailing 어 is still in composition (underlined) — this is the normal IME state, the user has not "finished" the word.
  4. Press Enter once, as you normally would to confirm the composition.

Observed:

  • A filter chip Title contains 한국어 is created immediately, and
  • the input is not empty — it still holds 어.
  • Pressing Enter again (the natural next thing to do, since text is visibly still in the box) produces a second chip Title contains 어.

Final state — the last composed character has been split off into its own filter:

[ Title contains 한국어 ]  [ Title contains 어 ]

Same phrase typed in English (hello + Enter) correctly produces a single Title contains hello chip and an empty input, so the divergence is specific to composition input.

Scripted verification (Playwright + CDP Input.imeSetComposition) against the hosted Storybook
=== BASELINE: ASCII typing + Enter ===
before Enter: {"value":"hello","chips":[]}
after Enter : {"value":"","chips":["Title: contains hello"]}

=== KOREAN IME ===
input value while composing  : {"value":"한국어"}      // 어 is composing
after composing-Enter keydown: {"value":"","chips":["Title: contains 한국어"]}
after compositionend commit  : {"value":"어","chips":["Title: contains 한국어"]}   // ← residue
after next Enter             : {"value":"","chips":["Title: contains 한국어","Title: contains 어"]}

Root cause

BaseTypeahead's keydown handler treats every Enter as a selection, with no composition guard:

https://github.com/facebook/astryx/blob/077087f68d5e5fc12b39218a67dfa6a29fa04bcd/packages/core/src/Typeahead/BaseTypeahead.tsx#L666-L671

case 'Enter':
  e.preventDefault();
  if (highlightedIndex >= 0 && highlightedIndex < results.length) {
    handleSelect(results[highlightedIndex]);
  }
  break;

The browser event order when an IME commits on Enter is:

  1. keydown — key: 'Enter', isComposing: true (legacy keyCode: 229)
  2. compositionend — the pending syllable is written into the input
  3. input

Step 1 reaches the handler above. handleSelect fires onChange(item) and setQuery(''), clearing the controlled input (BaseTypeahead.tsx#L557-L574). The composition is still live on that DOM node, so step 2 then commits 어 into the now-empty field — producing the leftover that becomes the second chip.

In PowerSearch the selected item is the synthetic content-search entry built in usePowerSearchSource.ts#L185-L198, which is unshifted to index 0 and therefore always the highlighted candidate — so the mis-fire is deterministic rather than dependent on what the user has highlighted.

Suggested fix

The repo already has the exact helper this needs, added in #3357:

// packages/core/src/hooks/useFocusTrap.ts
export function isImeKeyEvent(event: {...}): boolean   // isComposing || keyCode === 229

Applying it in BaseTypeahead.handleKeyDown — ideally as an early return covering Enter, Escape, ArrowUp/ArrowDown and Home/End, since an IME candidate window uses all of those — fixes PowerSearch, Tokenizer and Typeahead in one place. ChatComposerInput already does this (ChatComposerInput.tsx#L560-L566).

One more unguarded site worth fixing in the same pass — Enter-to-save in the filter edit popover, which will swallow the composition-commit Enter while typing a CJK filter value:

https://github.com/facebook/astryx/blob/077087f68d5e5fc12b39218a67dfa6a29fa04bcd/packages/core/src/PowerSearch/PowerSearchEditPopover.tsx#L702-L714

Possibly related: #3343 (accessibility & keyboard-management program), #4759 (i18n grapheme-safe string handling).

Astryx Version

@astryxdesign/[email protected] (reproduced on the hosted Storybook built from main)

Environment

Chrome / Chromium, Korean 2-Set IME. The same event sequence applies to Japanese and Chinese IMEs, and to Safari and Firefox, so this is expected to be browser-independent.

Activity

  1. added a commit that references this issue on Aug 11, 2026
    1135101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions