Skip to content

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Sep 10, 2025

This PR fixes an issue in React 19 where a warning is shown in the console:

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

This PR fixes that by doing 2 things:

  1. We make sure that we properly check for Fragment. We were relying on identity, but will now also check the underlying symbol.
  2. Make sure that the element we forward props to is not a Fragment either.

Test plan

  • All existing tests still pass (this codebase is using React 18 instead of 19,
    where we can't reproduce the warning)
  • Tested in a reproduction repo with React 19 that the warning is gone.

Before:

image

After:

image

Fixes: #3597
Fixes: #3351

In React 19, this `Component === Fragment` check was false for some
reason. Looking at them at runtime, shows this behavior in both React 18
and React 19

```ts
let x = <Fragment></Fragment>   // Instance of a Fragment
let y = <></>                   // Instance of a Fragment
let z = Fragment                // Fragment itself

console.log(x.type === Symbol.for('react.fragment'))  // true
console.log(y.type === Symbol.for('react.fragment'))  // true
console.log(z === Symbol.for('react.fragment'))       // true
```
We could potentially keep forwarding the props in case you have:

```ts
<Menu>
  <MenuButton>
    <>
      <>
        <>
          <>
            <button>To here</button>
          </>
        </>
      </>
    </>
  </MenuButton>
</Menu>
```

But we can do that in a followup PR _if_ it's needed...
Copy link

vercel bot commented Sep 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
headlessui-react Ready Ready Preview Comment Sep 10, 2025 10:47am
headlessui-vue Ready Ready Preview Comment Sep 10, 2025 10:47am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant