当我学习Remix时,我按照教程初始化了一个项目,但是当我打开Devtools时,我看到控制台上报告了几个错误。
Warning: Did not expect server HTML to contain a <div> in <html>.
Error: Hydration failed because the initial UI does not match what was rendered on the server.
*n
最可笑的是我打开了索引页Remix https://remix.run而且它的首页也报了同样的错误,所以我特别好奇补水是否成功以及为什么会出现这个错误
这是一个众所周知的 React 问题 https://github.com/facebook/react/issues/24430由浏览器扩展修改 DOM 引起。
在 Remix 中更明显 https://github.com/remix-run/remix/discussions/4902因为它能滋润整个肌肤<html />
,不仅仅是一个<div id="root" />
.
您可以通过使用未安装扩展程序(或隐身模式)的浏览器配置文件进行测试来确认是否是由浏览器扩展程序引起的。
Kiliman 在此演示了一种解决方法https://github.com/kiliman/remix-Hydration-fix https://github.com/kiliman/remix-hydration-fix其中涉及分别渲染头部和应用程序。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)