【问题标题】:Nuxt how to debug: The client-side rendered virtual DOM tree is not matching server-rendered contentNuxt如何调试:客户端渲染的虚拟DOM树与服务器渲染的内容不匹配
【发布时间】:2020-04-12 00:55:45
【问题描述】:

所以在我的 Nuxt universal-mode 应用程序中,有时会出现错误:

vue.runtime.esm.js:620 [Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content. This is likely caused by incorrect HTML markup, for example nesting block-level elements inside <p>, or missing <tbody>. Bailing hydration and performing full client-side render.

通常会出现第二个(实际上第二个有时会在没有第一个的情况下上升,而不是相反):

TypeError: Cannot read property 'toLowerCase' of undefined
    at emptyNodeAt (vue.runtime.esm.js:5851)
    at VueComponent.patch [as __patch__] (vue.runtime.esm.js:6492)
    at VueComponent.Vue._update (vue.runtime.esm.js:3933)
    at VueComponent.updateComponent (vue.runtime.esm.js:4048)
    at Watcher.get (vue.runtime.esm.js:4467)
    at new Watcher (vue.runtime.esm.js:4456)
    at mountComponent (vue.runtime.esm.js:4061)
    at VueComponent.Vue.$mount (vue.runtime.esm.js:8399)
    at init (vue.runtime.esm.js:3115)
    at hydrate (vue.runtime.esm.js:6362)

然后没有任何效果,因为当我单击应用程序中的另一个页面时,我得到:

client.js:134 TypeError: Cannot read property '_transitionClasses' of undefined
    at Array.updateClass (vue.runtime.esm.js:6799)
    at patchVnode (vue.runtime.esm.js:6298)
    at updateChildren (vue.runtime.esm.js:6177)
    at patchVnode (vue.runtime.esm.js:6303)
    at updateChildren (vue.runtime.esm.js:6177)
    at patchVnode (vue.runtime.esm.js:6303)
    at updateChildren (vue.runtime.esm.js:6177)
    at patchVnode (vue.runtime.esm.js:6303)
    at updateChildren (vue.runtime.esm.js:6177)
    at patchVnode (vue.runtime.esm.js:6303)

我基本了解为什么会发生这种情况,但当它发生时,我不知道从哪里开始,因为错误消息没有给出关于实际情况的单一提示 服务端版本和客户端版本的区别。

所以当这个问题出现时,我唯一能做的就是回滚到以前的 git 提交,直到问题自行修复......不幸的是,这不能很好地工作,因为有时错误会出现在它所在的代码版本上以前没有。

通常的解决方案是删除尽可能多的内容(.nuxtnode_install)并从头开始设置所有内容,希望它再次起作用。

最后我的评论/问题是:

  • client-side version doesn't match the server-side bug 出现时,为什么我们不能有更多关于有什么区别的详细信息?
  • 知道为什么这个错误会以这种不确定的方式作为一个整体发生吗?
  • 为什么这会破坏一切,而起初这只是一个警告?

对我来说,这对于生产应用程序来说是一个非常大的问题,因为它无法确定地修复。

【问题讨论】:

  • 我发现这可能是由于页面上任何无效的 HTML 语法或结构造成的,不一定只是在不匹配的组件中。例如,在
    中放置
    会导致服务器端出现额外的 #text 元素,并以难以追踪的方式强制水化保释。

标签: server-side-rendering nuxt.js


【解决方案1】:

显然在我的情况下,TypeError: Cannot read property 'toLowerCase' of undefined 错误在错误报告时上升。

我碰巧在另一个上下文中收到了The client-side rendered virtual DOM tree is not matching server-rendered content 警告,我确实收到了有用的解释,它并没有阻止执行,所以我会认为 bug-over-the-bug 运气不好,最终会自然修复,除非它会在未来重现。

如果您碰巧遇到同样的错误,不要绝望

首先,将TypeError: Cannot read property 'toLowerCase' of undefined错误报告给nuxt repo。

然后,为了调试,我鼓励您对模板的某些部分进行注释,以了解如何消除错误。在我的情况下,它在布局中,因此它一直发生,但是一旦我理解了这一点,我很快就找到了解释(尽管这是节点之间date-fns 的神秘不同行为环境和浏览器)。

祝你好运!

【讨论】:

  • 感谢您发布您的解决方案。注释掉对我有用(我在 nuxt-link 标签中有一个标签)。
猜你喜欢
  • 2021-11-02
  • 2021-05-27
  • 2019-01-14
  • 2020-02-03
  • 2020-05-13
  • 2020-05-16
  • 2021-06-08
相关资源
最近更新 更多