Skip to content

[combobox][otp field][menu] Share IME composition handling - #6062

Open
flaviendelangle wants to merge 3 commits into
mui:masterfrom
flaviendelangle:share-ime-composition
Open

flaviendelangle wants to merge 3 commits into
mui:masterfrom
flaviendelangle:share-ime-composition

Conversation

@flaviendelangle

Copy link
Copy Markdown
Member

ComboboxInput, OTPFieldInput and FilterDropdownInput (the filterable Menu input) each implemented the same IME composition handling:

  1. On compositionstart, buffer the input text, except on Android, where some keyboards treat all typing as one composition.
  2. On change while composing, update the buffer and skip the commit.
  3. On compositionend, clear the buffer and commit.

This PR moves that into internals/useImeComposition.ts. It returns the buffered value, the compositionstart/compositionend handlers, and bufferChange(value), which onChange calls first. Combobox keeps its extra open, close and highlight logic in its composing branch.

Fix: Combobox committed twice on Android

#2944 skipped compositionstart on Android but left compositionend unguarded. As a result, every time a composition ended, Combobox.Input called setInputValue again with the value onChange had already committed. That second call fired onInputValueChange twice 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, and OTPFieldInput.android.test.tsx asserts it. The shared hook applies the guard to all three. The new test in ComboboxInput.android.test.tsx fails without the fix (2 calls instead of 1).

Other differences between the copies

  • OTP Field tracked "composing" with 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.
  • OTP Field buffered slotValue on compositionstart. The hook uses event.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

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>
@flaviendelangle flaviendelangle added the type: bug It doesn't behave as expected. label Oct 22, 2026
@flaviendelangle flaviendelangle added the internal Behind-the-scenes enhancement. Formerly called “core”. label Oct 22, 2026
@flaviendelangle flaviendelangle added component: autocomplete Changes related to the autocomplete component. component: combobox Changes related to the combobox component. labels Oct 22, 2026
@flaviendelangle flaviendelangle self-assigned this Oct 22, 2026
@pkg-pr-new

pkg-pr-new Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

commit: 547f167

@code-infra-dashboard

code-infra-dashboard Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react ▼-90B(-0.02%) 🔺+11B(+0.01%)

Details of bundle changes

Performance

Total duration: 428.44 ms +8.96 ms(+2.1%) | Renders: 75 (+0) | Paint: 799.12 ms +33.00 ms(+4.3%)

Test Duration Renders
Scroll Area mount (300 instances) 42.43 ms 🔺+10.08 ms(+31.2%) 3 (+0)
Select open (500 options) 30.05 ms 🔺+5.31 ms(+21.4%) 14 (+0)
Slider mount (300 instances) 47.39 ms ▼-15.73 ms(-24.9%) 2 (+0)

12 tests within noise — details

Metric alarms

Test Metric Change
Scroll Area mount (300 instances) bench:paint 🔺 +13.61 ms
Select open (500 options) bench:paint 🔺 +14.91 ms
Select open (500 options) bench:paint#select-open 🔺 +14.91 ms

Check out the code infra dashboard for more information about this PR.

…ops entry

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Oct 22, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 409c73e
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6ad9cec9837e6a7aa775d1e9
😎 Deploy Preview https://deploy-preview-6062--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 547f167
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6ae1d693e0bd28a57dacdffb
😎 Deploy Preview https://deploy-preview-6062--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks

atomiks commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

PR review

Worth merging for the fix, once trimmed. The real bug: on Android, Combobox commits a second time when a composition ends. That fires onInputValueChange twice and resets the list scroll. On its own that fix is about 10 B. The shared hook costs +45 B gz (size bot). I found no behavior change across the three inputs apart from that fix, and the handlers merge in the same order as before. Native IME behavior wasn't tested.

Simplifications (1)

1. 🟡 The hook tracks "composing" twice

Location: packages/react/src/internals/useImeComposition.ts:14

const [composingValue, setComposingValue] = React.useState<string | null>(null);
const isComposingRef = React.useRef(false);

isComposingRef.current and composingValue != null are always set and cleared together. Composition events are discrete, so state is already updated before the next event, which OTP Field relied on before this PR and which the PR body itself argues.

Failure scenario: The extra ref, its writes, and an isComposingRef key that minification can't shorten add bytes to Combobox, Autocomplete, OTP Field and the Menu filter. That helps make a code-sharing PR +45 B gz.

Fix: Use state only: drop isComposingRef and have bufferChange, onCompositionEnd and the two call sites check composingValue != null. Re-check the size bot.

Verdict

Approve 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>
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: autocomplete Changes related to the autocomplete component. component: combobox Changes related to the combobox component. internal Behind-the-scenes enhancement. Formerly called “core”. PR: out-of-date The pull request has merge conflicts and can't be merged. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants