Open a Menu on click when the React Compiler compiles Ariakit's source
Context
While probing Escape handling for #7618 in the Next.js App Router app (nextjs/), a Menu didn't open when its MenuButton was clicked.
Problem
nextjs/ enables the React Compiler (reactCompiler: true in next.config.ts), and it resolves @ariakit/react to the package source, so the compiler also compiles Ariakit. In this app, a click on a MenuButton doesn't open its Menu, and aria-expanded stays false. ArrowDown on the same button opens the menu. Other popup disclosures open on click:
| Popup, opened with one click | Next.js app, compiler on | Next.js app, compiler off | Astro preview |
|---|---|---|---|
Menu |
Doesn't open | Opens | Opens |
Menu built with a Combobox |
Doesn't open | Opens | Opens |
Popover |
Opens | Opens | Opens |
Dialog with modal={false} |
Opens | Opens | Opens |
ComboboxSelect |
Opens | Opens | Opens |
Select |
Opens | Opens | Opens |
The failure needs the compiler to compile Ariakit's source. With a copy of the menu-combobox example as a page:
| Compiler setup | Click opens the menu |
|---|---|
reactCompiler: true, the app's setting |
No |
reactCompiler: true, with "use no memo" in the example file |
No |
reactCompiler: { compilationMode: "annotation" }, with "use memo" only in the example file |
Yes |
reactCompiler: false |
Yes |
Reproduction
"use client";
import * as Ariakit from "@ariakit/react";
export default function Page() {
return (
<Ariakit.MenuProvider>
<Ariakit.MenuButton>Open</Ariakit.MenuButton>
<Ariakit.Menu>
<Ariakit.MenuItem>Item 1</Ariakit.MenuItem>
<Ariakit.MenuItem>Item 2</Ariakit.MenuItem>
</Ariakit.Menu>
</Ariakit.MenuProvider>
);
}- Add the page to
nextjs/app, run the Next.js dev server, and open the page. - Click Open.
Expected: the menu opens. Actual: nothing happens.
Pre-existing on main
Yes. The first table was measured on main at 53d5e0b. The second table was measured on main at c8010f7, before #7618, and on the #7618 branch, with the same results. All runs used Chrome, the Next.js 16.2.12 dev server (Turbopack), React 19.3.0, and babel-plugin-react-compiler 1.0.0. The first table comes from a temporary page that rendered the menus next to other popups. The reproduction page above renders only the menu, and it fails the same way on main at 53d5e0b in 3 of 3 runs. The copy of the example has no stylesheet import, because the Next.js app can't compile its Tailwind utilities, and it uses a plain filter instead of matchSorter, because nextjs/ doesn't depend on match-sorter.
Why #7618 can finish without it
#7618 is merged. It didn't cause this problem, and the menus fail the same way before it. Its tests run in the Astro previews, which don't use the compiler.
Expected outcome
A click on a MenuButton opens its Menu when the React Compiler compiles Ariakit's source, as it does without the compiler.
Notes for the fix
- The cause isn't known yet. Compiling only the page doesn't break the click, so compiled Ariakit source is involved. Other disclosures open on click, so the problem is probably in code that only
MenuButtonorMenuruns. - It's not verified whether apps that install the published package are affected. Next.js compiles Ariakit's source here because the workspace package resolves to
src/index.ts.
Workaround
See the verified annotation-mode workaround.
Source: ariakit/ariakit