Repository navigation
[combobox][otp field][menu] Share IME composition handling - #6062
flaviendelangle wants to merge 3 commits into
Conversation
Combobox, OTP Field and the filterable Menu input each buffered IME composition text the same way. Move it into `useImeComposition`. Combobox was the only one without a guard on `compositionend`, so on Android it committed the input value a second time when a composition ended. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
commit: |
Bundle size
PerformanceTotal duration: 428.44 ms +8.96 ms(+2.1%) | Renders: 75 (+0) | Paint: 799.12 ms +33.00 ms(+4.3%)
12 tests within noise — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
…ops entry Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
PR reviewWorth merging for the fix, once trimmed. The real bug: on Android, Combobox commits a second time when a composition ends. That fires Simplifications (1)1. 🟡 The hook tracks "composing" twiceLocation: const [composingValue, setComposingValue] = React.useState<string | null>(null);
const isComposingRef = React.useRef(false);
Failure scenario: The extra ref, its writes, and an Fix: Use state only: drop VerdictApprove after nits - the Android fix is correct; the shared hook should not cost more than the copies it replaces. 🤖 Review generated with Claude Code |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ComboboxInput,OTPFieldInputandFilterDropdownInput(the filterable Menu input) each implemented the same IME composition handling:compositionstart, buffer the input text, except on Android, where some keyboards treat all typing as one composition.changewhile composing, update the buffer and skip the commit.compositionend, clear the buffer and commit.This PR moves that into
internals/useImeComposition.ts. It returns the buffered value, thecompositionstart/compositionendhandlers, andbufferChange(value), whichonChangecalls first. Combobox keeps its extra open, close and highlight logic in its composing branch.Fix: Combobox committed twice on Android
#2944 skipped
compositionstarton Android but leftcompositionendunguarded. As a result, every time a composition ended,Combobox.InputcalledsetInputValueagain with the valueonChangehad already committed. That second call firedonInputValueChangetwice and re-ran the typed-input side effects, including resetting the list scroll to the top. OTP Field (#5098) and the filterable Menu (#5527) already guard against this, andOTPFieldInput.android.test.tsxasserts it. The shared hook applies the guard to all three. The new test inComboboxInput.android.test.tsxfails without the fix (2 calls instead of 1).Other differences between the copies
composingValue != null(state). The hook uses a ref, as the other two did. Composition events are discrete, so React re-renders before the next event and both give the same answer.slotValueoncompositionstart. The hook usesevent.currentTarget.value, which is the same value: the input is controlled, and the IME hasn't edited it yet when the event fires.🤖 Generated with Claude Code