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.

Getting warning: Did not expect server HTML to contain a <div> in <div>

See original GitHub issue

Hello 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
nrei0commented, Feb 2, 2020

Hello. I have seems like same problem. const AsyncIcon = loadable(({ name }: AsyncIconProps) => import(…/…/static/svg/${name}.svg), { ssr: true, fallback: <span>Loading</span> });

  • If ssr: false works well, SSR returns fallback, Client renders fallback and then loads chunks and display actual component.
  • If 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.
2reactions
fuzingcommented, Dec 9, 2019

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

Read more comments on GitHub >

github_iconTop 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 >

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