Skip to content

SSR error with <Menu.Button>: Prop id did not match. #1961

@ShaunDychko

Description

@ShaunDychko

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

v1.7.3

What browser are you using?

Chrome

Reproduction URL

https://github.com/ShaunDychko/headlessui-reproduce-menu-button-error

To reproduce

  1. clone the repo
  2. npm run develop
  3. visit http://localhost:8000
  4. inspect the browser console.

Describe your issue

The console logs the error:

Warning: Prop `id` did not match. Server: "headlessui-menu-button-:Rkp:" Client: "headlessui-menu-button-:R2j5:"
    at button
    at eval (webpack-internal:///./node_modules/@headlessui/react/dist/components/menu/menu.js:23:3867)
    at C (webpack-internal:///./node_modules/@headlessui/react/dist/internal/open-closed.js:8:255)
    at eval (webpack-internal:///./node_modules/@headlessui/react/dist/components/menu/menu.js:23:2487)
    at MyDropdown

This occurs when Gatsby's DEV_SSR flag is enabled in gatsby-config.js, which causes server side rendering when the page is refreshed. It occurs with react@^18, but not with react@^17. It's probably related to https://github.com/tailwindlabs/headlessui/blob/main/packages/%40headlessui-react/src/hooks/use-id.ts

I believe this causes React to re-render the page, which is consequential since it clears the cache from RTK Query and causes dynamic UI elements to flash between states while they're waiting for server data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions