Getting warning: Did not expect server HTML to contain a <div> in <div>
See original GitHub issueHello there, thank you for this remarkable library 😃
I am using this library with razzle@3.0.0 (React 16.9.0) and I’ve successfully done all four steps from this guide: https://www.smooth-code.com/open-source/loadable-components/docs/server-side-rendering/#guide
But, in dev mode
, I am still getting this warning Warning: Did not expect server HTML to contain a <div> in <div>.
in browser console (production build seems to be ok, but there might be supressed warning). So SSR HTML does not match HTML
hydrated on client side.
After isolation of this this issue, the cause is this code: const Home = loadable(() => import('./Home'))
Could you give me some hints how to solve it please?
Thank you! 🙏
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:15 (3 by maintainers)
Top Results From Across the Web
Did not expect server HTML to contain a <div ... - Stack Overflow
The cause was hard to find because Client and Server rendered the same HTML. My Solution:
Read more >Warning: Did not expect server HTML to contain a <div> in ...
I guess it is because there is no content under the root tag, so the resources of the current page are loaded automatically....
Read more >SSR - Did not expect server HTML to contain a <div> in <div>
From my research it means the tree rendered on server side and client side is not the same… which is true as on...
Read more >Did not expect server HTML to contain a <div> in <div>."-Reactjs
I found a solution. If the modal show state comes true first, it produces this warning. So I made it first undefined then...
Read more >Kitty Giraudel on Twitter: "Warning: Did not expect server ...
Warning : Did not expect server HTML to contain a <div> in <div>. Thanks, React. Helpful as always. ... Struggled with the same...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello. I have seems like same problem.
const AsyncIcon = loadable(({ name }: AsyncIconProps) => import(
…/…/static/svg/${name}.svg), { ssr: true, fallback: <span>Loading</span> });
ssr: false
works well, SSR returns fallback, Client renders fallback and then loads chunks and display actual component.ssr: true
, SSR returns actual component, which is correct, BUT Client is still trying fetch chunks which is incorrect and of course difference that on Client displays Fallback first.I suspect that you might be running into the same problem as me (I haven’t yet found a solution)… however, it appears that when code splitting with webpack, webpack’s import returns an unresolved Promise even when the imported module/chunk is already downloaded. The promise resolves a short time later, but not until after the first react render, meaning that your loadable component will render its fallback, or null (which is likely different to what you just rendered on the server).
On the client:
console.log(yourReactParentNode.innerHTML);
hydrate(........);
console.log(yourReactParentNode.innerHTML);
May or may not confirm this (there’s a time race, so it may NOT). Even if webpack were to return a resolved Promise in the event that the module/chunk is already present in the browser, it’s unclear whether this would solve the problem because the Promise’s “then” method may not be called until some time later (JS implementation dependent).
So, for example, in chrome:
Promise.resolve().then(() => { console.log("Resolved"); });
console.log("After");
results in:After
Resolved