question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10

github_iconTop GitHub Comments

2reactions
lgraubnercommented, May 3, 2022

The latest release does fix it, indeed. Thanks!

2reactions
MTaghiniacommented, May 1, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React 18: Hydration failed because the initial UI does not ...
Hydration failed when the children was dangerously set inner HTML . Got rid of the component, and it works fine now. (I could...
Read more >
react 18 hydration error | The AI Search Engine You Control
Error : Hydration failed because the initial UI does not match what was rendered on the server. error message when using the headlessui...
Read more >
Strict Mode - React
StrictMode currently helps with: Identifying components with unsafe lifecycles; Warning about legacy string ref API usage; Warning about deprecated findDOMNode ...
Read more >
Using Ultra, the new React web framework - LogRocket Blog
Wrapping React Suspense around a component will enable selective hydration. Selective hydration will start hydrating HTML before JavaScript code ...
Read more >
react-hydration-error - Next.js
In general this issue is caused by using a specific library or application code that is relying on something that could differ between...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found