Repository navigation
Description
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
- Switch the OS input source to a Korean IME (2-Set / 두벌식).
- Click the PowerSearch input (
Type to search by title, or pick a field...). - Type
한국어. The trailing어is still in composition (underlined) — this is the normal IME state, the user has not "finished" the word. - 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:
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:
keydown—key: 'Enter',isComposing: true(legacykeyCode: 229)compositionend— the pending syllable is written into the inputinput
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 === 229Applying 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:
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
fix(Typeahead): guard Enter/Escape/arrow keys against IME composition (…