I'm using the React 16 beta (react-fiber) with server side rendering
What I am to understand this to mean?
warning.js:36 Warning: Did not expect server HTML to contain a <div> in <div>.
I'm using the React 16 beta (react-fiber) with server side rendering
What I am to understand this to mean?
warning.js:36 Warning: Did not expect server HTML to contain a <div> in <div>.
Looking for that error in the react code it seems that this happens when the SSR html can't be rehydrated.
So you are somehow initially rendering a different tree on the client vs the server.
warnForDeletedHydratableElement
and message Did not expect server HTML to contain a ...
. The warning could be definitely more verbose... –
Layamon This is odd but for me the issue was my password manager extension (LastPass) injecting some HTML where I have some input fields... I disabled the extension and the error was gone 🤷🏽♂️
Just change express response from
<body>
<div id="root">
${markup}
</div>
</body>
to
<body>
<div id="root">${markup}</div>
</body>
Remove space between tags
classNames
. This is not a great solution. –
Rundown Looking for that error in the react code it seems that this happens when the SSR html can't be rehydrated.
So you are somehow initially rendering a different tree on the client vs the server.
warnForDeletedHydratableElement
and message Did not expect server HTML to contain a ...
. The warning could be definitely more verbose... –
Layamon I faced the same warning while using Modal in Next.js. I was working to create a popup on the main page.
I found a solution. If the modal show state comes true first, it produces this warning. So I made it first undefined then I set it true after the page rendered . The code is below.
const [modalShow, setModalShow] = React.useState();
useEffect(() => {
if ( modalShow === undefined ) {
setModalShow(true)
}
}, [modalShow])
I had this issue, I solved it where I changed this:
<div>
<Header />
{children}
</div>
to this:
<div>
<Header />
<div>{children}</div>
</div>
I found out that my problem was caused by the component not being ready to render, so it's a well-known issue that is fixed like that.
export const ComponentWithIssue = () => {
const [isLayoutReady, setIsLayoutReady] = useState(false);
useEffect(() => {
setIsLayoutReady(true);
}, []);
return (
isLayoutReady && <div>Your JSX structure here</div>
);
};
My issue was react-loadable: The code used LoadableComponent
for client only which wrapped each of my React-Component in client.
The cause was hard to find because Client and Server rendered the same HTML.
My Solution:
node 16.x
import
I am developing my project with Next.js in version 13.4.4, and at the moment of entering an <input/>
in my component I was getting this header error.
However, when looking at the Dom of my browser, I found that I was automatically adding a <div></div>
from the lastPass application, which is a password management extension.
I removed the extension and was able to fix the error, and everything works perfectly so far.
For me adding the name
property to my <input>
elements fixed this issue.
I assume LastPass was looking for the email and password values and caused this error as suggested by others.
I had the same fault, i was trying some stuff and added html element directly to the root layout.
return (
<html lang="en">
<body>
{children}
//was added here some html element who gives the error
</body>
</html>
);
The placeholder
property on an <input />
tag also triggers this error... even in a static HTML component. Apparently, there must be an initial state in the browser that causes the mismatch. I guess I'll set that after load, how lame!
I'm using Next.js 12. In this case, stopping the dev server, deleting the .next
directory, and restarting the dev server solved the issue.
This happened following a fix that I did to some Styled Components. I guess something was off with the Next.js cache following the fix, so deleting it helped.
I have this problem while working with a modal.
const [modalOpen, setModalOpen] = React.useState(true)
Solved this by just change the default state to false
© 2022 - 2024 — McMap. All rights reserved.