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]: The example code for hydrateRoot seems to be wrong #6703

Closed
mikehearn opened this issue Mar 22, 2024 · 1 comment
Closed

[Bug]: The example code for hydrateRoot seems to be wrong #6703

mikehearn opened this issue Mar 22, 2024 · 1 comment

Comments

@mikehearn
Copy link

Summary

The example code for hydrateRoot seems to be wrong.

Page

https://react.dev/reference/react-dom/server/renderToReadableStream#rendering-a-react-tree-as-html-to-a-readable-web-stream

Details

I am implementing React SSR and discovered that I have to use the following construct:

hydrateRoot(document.documentElement, <App/>);

not

hydrateRoot(document, <App/>);

as shown in the docs. If I try the latter I get hydration errors due to mismatches on top level tags like head or body. The App component returns <html> as the root, as it says to do in the docs.

@mikehearn
Copy link
Author

Of course, after wrestling with this for an afternoon I find the issue five minutes after filing a bug ... using document does work, but I was actually constructing the components with React.createElement and not adding null as a third parameter.

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

No branches or pull requests

1 participant