headlessui: "Invalid prop `data-headlessui-state` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props."

What package within Headless UI are you using?

"@headlessui/react": "0.0.0-insiders.fbad6a9",

What browser are you using?

For example: Chrome

Reproduction URL

I was not able to create a minimal reproduction, yet. Will update once I have one. Wanted to share the issue now so others can search for it and help.

Describe your issue

I am testing React 19, Next 15, React Compiler in our Project. When rendering our app I am getting multiple console errors in the browser like…

Warning: Invalid prop `data-headlessui-state` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.
    at c (webpack-internal:///(app-pages-browser)/./node_modules/@headlessui/react/dist/internal/open-closed.js:17:18)
    at u (webpack-internal:///(app-pages-browser)/./node_modules/@headlessui/react/dist/internal/close-provider.js:13:18)
    at me (webpack-internal:///(app-pages-browser)/./node_modules/@headlessui/react/dist/components/disclosure/disclosure.js:111:24)
    at SelectDatasets (webpack-internal:///(app-pages-browser)/./src/app/regionen/[regionSlug]/_components/SidebarLayerControls/StaticDatasets/SelectDatasets.tsx:32:72)
    at nav
    …

I am seeing the same error with other libraries, so this might be a temporary or a new issue with React 19 or Next 15 or React Compiler.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 13
  • Comments: 20 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Same issue happening in React 19 RC

Solution that worked for me is to add the as="div" prop to the <Disclosure /> component like this: <Disclosure {...rest} as="div">

Happening in React 19 with Vite 6, happening in Listbox. Using as="div" resolved the issue, but Idk whether there’s any side effect

Got it: https://stackblitz.com/edit/vitejs-vite-x9bjfwzm?file=src%2Fmain.tsx

I simplified it down from this file.

import { createRoot } from 'react-dom/client';
import {
  Listbox,
  ListboxButton,
  ListboxOption,
  ListboxOptions,
} from '@headlessui/react';

createRoot(document.getElementById('root')!).render(
  <Listbox>
    {/* this fragment is the problem! */}
    <>
      <ListboxButton>Select an option</ListboxButton>
      <ListboxOptions>
        <ListboxOption value="hi">Hello</ListboxOption>
        <ListboxOption value="v2">Another</ListboxOption>
      </ListboxOptions>
    </>
  </Listbox>
);

The fragment here in minimal form is pointless, but in practice the point is to do this:

<Listbox>
  {({ open }) => (
    <>
      {/* label + button + options depend on open, etc. */}
    </>
  )}
</Listbox>
Image

This can be mitigated by replacing the fragment with <div> with display: contents style

Happening with React 19 and Next 15.1.6 when using Menu. Using as="div" resolved the issue. Any updates if this gets fixed?

Hey!

Can anyone running into this issue provide a minimal reproduction repo? Inside of Headless UI we check whether a Fragment was used or not. Only thing I can think of is that there is a different instance of Fragment, but looking at the React Compiler it seems like they just use Fragment from the react package directly.

Would love to get it fixed, so if anyone can share a reproduction that will be greatly appreciated.

This is happening to me in "react": 18.3.1 not 19… just wanted to share. And we’re not using the Disclosure component.