Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Tab Component, Hydration error on React 18 #1375

Closed
mirshko opened this issue Apr 28, 2022 · 10 comments
Closed

[Bug]: Tab Component, Hydration error on React 18 #1375

mirshko opened this issue Apr 28, 2022 · 10 comments

Comments

@mirshko
Copy link

mirshko commented Apr 28, 2022

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

v1.60

What browser are you using?

Safari

Reproduction URL

https://codesandbox.io/s/cool-yonath-qeouqc?file=/pages/index.js

Describe your issue

Error: Hydration failed because the initial UI does not match what was rendered on the server. error message when using the headlessui Tab component.

@RobinMalfait
Copy link
Member

Hey! Thank you for your bug report!
Much appreciated! 🙏

I don't know if there is much we can do here. We are using React 18's useId hook, and the produced IDs are different on the server compared to the client. In the console you also have this warning:

Warning: ReactDOM.hydrate is no longer supported in React 18. Use hydrateRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot

Fixing that might probably solve the issue.

Here is an example of our playground where we don't have hydration issues and this behaviour works as expected: https://headlessui-react-fglvz9cc1-tailwindlabs.vercel.app/tabs/tabs-with-pure-tailwind

@MTaghinia
Copy link

MTaghinia commented Apr 30, 2022

Hey! Thank you for your bug report! Much appreciated! 🙏

I don't know if there is much we can do here. We are using React 18's useId hook, and the produced IDs are different on the server compared to the client. In the console you also have this warning:

Warning: ReactDOM.hydrate is no longer supported in React 18. Use hydrateRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot

Fixing that might probably solve the issue.

Here is an example of our playground where we don't have hydration issues and this behaviour works as expected: https://headlessui-react-fglvz9cc1-tailwindlabs.vercel.app/tabs/tabs-with-pure-tailwind

The provided example also has this problem and it shows the hydration error in the console.
There is a problem with id created with useId hook which cause hydration error with nextjs and react 18.

@lgraubner
Copy link

This also happens with react@17.0.2, getting the following warning in the browser console:

Expected server HTML to contain a matching <button> in <div>.

@mirshko
Copy link
Author

mirshko commented May 3, 2022

@RobinMalfait I dont think this issue is closed then, or am I missing something?

@RobinMalfait
Copy link
Member

This should be fixed by #1393, and is available in the latest release (1.6.1).
If you have other issues, please open a new issue with a reproduction repo / CodeSandbox attached 👍

@lgraubner
Copy link

The latest release does fix it, indeed. Thanks!

@ludusrusso
Copy link

Hi! I have a similar issue with Popover componente. React 18.1.0 with Next 12.1.6 and @headlessui/react 1.6.2

@justinwaite
Copy link

I also continue to see this issue with React 18.2.0, Remix 1.6.0, and @headlessui/react 1.6.5

@Tosinkoa
Copy link

Tosinkoa commented Jul 6, 2022

I am getting rehydration error, pls help

@RobinMalfait
Copy link
Member

If anyone still experiences an issue with this, please open a new issue with a minimal reproduction repo attached. Sadly, it's impossible to help without info!

@tailwindlabs tailwindlabs locked as resolved and limited conversation to collaborators Jul 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants