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

Fix hydration of components inside <Suspense> #2633

Merged
merged 4 commits into from
Aug 2, 2023

Conversation

thecrypticace
Copy link
Contributor

@thecrypticace thecrypticace commented Aug 1, 2023

Previously, when dealing with SSR, we had a hook that would basically force a re-render of all components on page load. This also used some global state so we didn't unnecessarily cause re-renders for components that were mounting after the page had already loaded.

However, because <Suspense> delays hydration this is no longer a viable solution. Thankfully most of our components don't have to do much in the way of "differences" when rendering on the server. The main exceptions are our internal <Portal> component and the <Transition> component.

We've implemented some component specific tweaks for those and removed the rest of the uses of that hook to work around this problem. Now, it only matters technically, with our internal version of useId for React < 18 which doesn't have Suspense — meaning there's no hydration problems there.

Fixes #2400

@vercel
Copy link

vercel bot commented Aug 1, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
headlessui-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 2, 2023 2:18pm
headlessui-vue ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 2, 2023 2:18pm

thecrypticace and others added 4 commits August 2, 2023 16:16
It’s only useful for the useId hook. It is not compatible with `<Suspense>` because hydration is delayed then.
Since Portals cannot SSR the first render MUST also return `null`. React really needs an `isHydrating` API.
This fixes a problem where clicks were assumed to be outside because of the delayed `<Portal>` render. The second portal render doesn’t cause the dialog to re-render thus the initial ref values were stale.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transition issue with React Suspense
2 participants