Skip to content

[combobox] Two selection-changing clicks dispatched before a re-render can clobber each other in multiple mode #5759

Closed

Description

@jeffredodd

Current behavior

In multiple mode with Combobox.Chips, two selection-changing interactions (chip-remove clicks, or a chip-remove plus an item-press) that are both dispatched before React commits a re-render between them can silently corrupt the selection — either the wrong chip survives, or one of the two intended changes is discarded entirely.

This traces to two places that each read selectedValue at handler-invocation time and call setSelectedValue/store.state.setSelectedValue/store.context.setSelectedValue directly, rather than through an atomic update against the store's latest state:

  • combobox/chip-remove/ComboboxChipRemove.js, removeChip():

    const removedItem = selectedValue[index];
    ...
    store.context.setSelectedValue(selectedValue.filter((_, i) => i !== index), eventDetails);

    Removal is by positional index into a snapshot of selectedValue, not by the value the chip actually represents.

  • combobox/root/AriaCombobox.js, the multiple branch of the item-press handler (handleSelection):

    const currentSelectedValue = Array.isArray(selectedValue) ? selectedValue : [];
    const isCurrentlySelected = selectedValueIncludes(currentSelectedValue, itemValue, isItemEqualToValue);
    const nextValue = isCurrentlySelected ? removeItem(currentSelectedValue, itemValue, isItemEqualToValue) : [...currentSelectedValue, itemValue];
    setSelectedValue(nextValue, eventDetails);

When two such handlers both run against the same pre-update selectedValue snapshot (because the first one's state update hasn't committed yet), whichever setSelectedValue call is processed last overwrites the first's effect using stale data.

Reproduction

Confirmed deterministically (16/16 runs across two variants) in real Chromium via Playwright, dispatching two native .click() calls back-to-back in the same tick (no await/settle between them) against the "multi-select with chips" demo pattern:

function MultiSelectChips() {
  const [value, setValue] = React.useState(['Alpine', 'Debian', 'Ubuntu']);
  const anchor = useComboboxAnchor(); // ref to the Chips element
  return (
    <Combobox.Root items={['Alpine', 'Debian', 'Ubuntu', 'Fedora', 'Arch']} multiple value={value} onValueChange={setValue}>
      <Combobox.Chips ref={anchor}>
        {value.map(v => (
          <Combobox.Chip key={v}>
            {v}
            <Combobox.ChipRemove aria-label="Remove" />
          </Combobox.Chip>
        ))}
        <Combobox.Input />
      </Combobox.Chips>
      <Combobox.Portal>
        <Combobox.Positioner anchor={anchor.current}>
          <Combobox.Popup>
            <Combobox.List>{item => <Combobox.Item key={item} value={item}>{item}</Combobox.Item>}</Combobox.List>
          </Combobox.Popup>
        </Combobox.Positioner>
      </Combobox.Portal>
    </Combobox.Root>
  );
}
// Dispatched synchronously, no await between the two clicks:
const alpineRemove = document.querySelector('[chip="Alpine"] button');
const debianRemove = document.querySelector('[chip="Debian"] button');
alpineRemove.click();
debianRemove.click();
// Expected: [] (both removed)
// Actual, 8/8 runs: ['Alpine'] — Debian is removed correctly, but Alpine
// survives even though its own remove button was clicked directly.

A second variant — remove one chip, then immediately click a filtered Combobox.Item (both dispatched synchronously) — also races, in the other direction: the removal is discarded entirely while the item-press's addition still lands (using the stale pre-removal selectedValue as its base).

Does not reproduce with sequential/awaited interactions — confirmed both under @testing-library/react (userEvent, and even fireEvent back-to-back, since act() forces a commit between each dispatched event) and in real Chromium with any await/settle between the two clicks. It requires two dispatches landing within the same pre-commit window, which is why it's easy to hit via automation but harder (though not impossible — see below) via a real pointer.

Why this is likely user-reachable, not just a synthetic-timing artifact

Found while investigating a real user report against a design system built on this component (docker/trident#852): a screen recording of someone filtering a multiple Chips combobox and picking/removing several items in quick succession showed a chip disappearing without a corresponding remove click, and a filtered pick failing to commit. multiple-mode Chips filtering also, until #5362, force-closed the popup on every filtered pick — which meant reopening and re-filtering between every single selection, real-world timing that plausibly narrows the gap between two clicks enough to land inside the pre-commit window on a slower render (e.g. a heavier filtered re-render). #5362 helps by removing that forced reopen loop, but doesn't address the underlying race.

Expected behavior

Two selection-changing interactions landing close together should never silently drop or misapply either one — at minimum, the second handler should compute against the current store state (or the store should serialize/queue these updates) rather than each closing over its own stale snapshot.

Base UI version

1.8.0 (confirmed the same code shape, just moved around a store.state → store.context/useState refactor, back to 1.6.0)

Which browser are you using?

Chromium (via Playwright), also affects the underlying React state model so isn't browser-specific

Which OS are you using?

Linux

Additional context

Happy to share the Playwright repro script if useful.

Activity

  1. jeffredodd commented on Sep 18, 2026

    @jeffredodd
    Author

    Closing — withdrawing this while I re-verify against the original report it was based on. Apologies for the noise.

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

    component: comboboxChanges related to the combobox component.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions