Skip to content

[select] Mouse selection is a no-op in dev StrictMode #4698

Closed

Description

@rachel-church

Bug report

Current behavior

When a Base UI <Select> is rendered in a React StrictMode dev environment (e.g. a Next.js dev server, which has reactStrictMode: true by default), clicking a Select.Item with the mouse is a no-op:

  • The dropdown opens normally and the CSS :hover style appears on items.
  • Clicking an item does not fire onValueChange. The trigger keeps its placeholder.
  • Depending on which item is hovered, the dropdown either stays open or closes without committing.
  • Keyboard navigation (ArrowDown + Enter) works correctly.
  • Production builds (no StrictMode → single mount) work correctly.

The root cause appears to be in useCompositeListItem / CompositeList: under StrictMode, the cleanup effect that sets elementsRef.current = [] runs (twice, as expected), but in the Next.js dev runtime the items' ref callbacks do not re-fire to repopulate elementsRef. As a result listRef.current.indexOf(liveOptionNode) === -1 inside useListNavigation.syncCurrentTarget, so activeIndex never updates on hover and SelectItem.onClick bails on its pointerTypeRef.current !== 'touch' && !highlighted guard.

Expected behavior

Hovering a Select.Item updates activeIndex so a subsequent click commits the value — regardless of React StrictMode. Equivalently: useCompositeListItem registration should be StrictMode-resilient so the live DOM nodes always end up in listRef.current.

Reproducible example

Steps:

  1. Open the StackBlitz (it boots next dev automatically).
  2. Click the Pick a flavor trigger.
  3. Click any flavor — the trigger keeps showing the placeholder.

The component tree is:

"use client";
import * as React from "react";
import { Select } from "@base-ui/react/select";
import { useState } from "react";

export default function Page() {
  const [value, setValue] = useState<string | null>(null);
  return (
    <React.StrictMode>
      <Select.Root value={value} onValueChange={setValue}>
        <Select.Trigger>
          <Select.Value placeholder="Pick a flavor" />
        </Select.Trigger>
        <Select.Portal>
          <Select.Positioner>
            <Select.Popup>
              <Select.Item value="strawberry">Strawberry</Select.Item>
              <Select.Item value="pistachio">Pistachio</Select.Item>
              <Select.Item value="hazelnut">Hazelnut</Select.Item>
            </Select.Popup>
          </Select.Positioner>
        </Select.Portal>
      </Select.Root>
    </React.StrictMode>
  );
}
Image

Base UI version

@base-ui/react@1.4.1. Also reproduced on 1.4.0 and 1.3.0.

Which browser are you using?

Chrome 130

Which OS are you using?

Mac OS

Which assistive tech are you using (if applicable)?

N/A — bug is mouse-only; keyboard interaction works.

Additional context

Direct evidence: elementsRef is wiped in dev

Inspecting the CompositeList state via the React fiber while the dropdown is open in the StackBlitz repro:

elementsRef.current; // [null, null, null] — same length as the rendered options, all empty
options.every((o) => o.tabIndex === -1); // true

The handler is attached but a no-op

Native mousemove / pointermove events fire on the [role="option"] element, and the React onMouseMove prop from useListNavigation's getItemProps is attached. But invoking it manually with the live DOM node as currentTarget does not update tabIndex:

const opt = document.querySelector('[role="option"]'); // a non-selected option
const reactPropsKey = Object.keys(opt).find((k) =>
  k.startsWith("__reactProps"),
);
opt[reactPropsKey].onMouseMove({
  currentTarget: opt,
  target: opt,
  type: "mousemove",
  pointerType: "mouse",
  nativeEvent: new MouseEvent("mousemove"),
});
// Next.js dev / StrictMode: opt.tabIndex stays -1
// Vite + non-StrictMode build: opt.tabIndex becomes 0

That isolates the failure to syncCurrentTarget's listRef.current.indexOf(event.currentTarget) returning -1, which only happens when elementsRef no longer contains the live DOM nodes.

Where the bug does and does not manifest

Environment Repro?
Next.js 14 dev (StackBlitz repro above) ✅ Yes
Next.js 14 production build (next build && next start) ❌ No
Plain Vite + React 18.2.0 + <React.StrictMode> ❌ No
Storybook (Webpack, no React Refresh) ❌ No

So the bug needs the combination of:

  • React ~18.3.x in StrictMode
  • Next.js dev (React Refresh + SSR/hydration as the initial mount)

A clean <React.StrictMode> wrapper alone (Vite, Storybook) does not trigger it — likely because Next.js's React Refresh runtime wraps "use client" modules in a way that interferes with ref re-attachment after StrictMode's simulated unmount, or because hydration's effect ordering differs from createRoot-only mount.

Differences between NextJS and Plain React

Next.js App Router uses hydrateRoot instead of createRoot for the initial page load. Hydration attaches React to pre-existing server-rendered DOM instead of creating new DOM nodes. This changes the relationship between when ref callbacks fire and when layout effects fire. During hydration, React walks the existing DOM tree and associates fibers with existing elements.

Workaround for downstream apps

  • Disable reactStrictMode on routes containing a Select, or
  • Run a production build for QA-style testing of selection.

Proposed fix

A patch is in flight that hardens CompositeList / useCompositeListItem to re-populate elementsRef and labelsRef from the internal sortedMap on every effect run, so the wipe-without-reattach cycle recovers automatically. Includes a unit test that simulates the wipe directly and verifies elementsRef.indexOf(liveNode) succeeds after subsequent registers.

Activity

  1. added
    status: waiting for maintainer
    on Apr 28, 2026
  2. added
    component: select
    on Apr 28, 2026
  3. changed the title [-][Select] Mouse selection is a no-op in dev StrictMode[/-] [+][select] Mouse selection is a no-op in dev StrictMode[/+] on Apr 28, 2026
  4. added
    type: bug
    and removed
    status: waiting for maintainer
    on Apr 28, 2026
  5. github-actions commented on Jul 17, 2026

    @github-actions

    This fix will be available in the next npm release of Base UI.

    In the meantime, you can try it out on our Canary release channel:

    npm i https://pkg.pr.new/@base-ui/react@5256
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: selecttype: bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions