React 16 warning “warning.js:36 Warning: Did not expect server HTML to contain a <div> in <div>.”

本小妞迷上赌 提交于 2019-11-30 16:40:19

问题


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

回答1:


Looking for that error in the react code it seems that this happens when the SSR html can't be rehydrated.

https://github.com/facebook/react/blob/7a60a8092144e8ab2c85c6906dd4a7a5815cff1f/src/renderers/dom/fiber/ReactDOMFiberComponent.js#L1022

So you are somehow initially rendering a different tree on the client vs the server.




回答2:


Just change express response from

<body>
    <div id="root">
        ${markup}
    </div>
</body>

to

<body>
    <div id="root">${markup}</div>
</body>

Remove space between tags



来源:https://stackoverflow.com/questions/45350360/react-16-warning-warning-js36-warning-did-not-expect-server-html-to-contain-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!