fix(Suspense): properly fix #6416

previous fix caused regressions in nuxt
This commit is contained in:
Evan You 2023-12-13 17:56:58 +08:00
parent 33159a5916
commit 0db336ff6c
3 changed files with 14 additions and 8 deletions

View File

@ -1684,7 +1684,9 @@ describe('Suspense', () => {
expect(serializeInner(root)).toBe('<div>async</div>')
viewRef.value = 1
await nextTick() //TypeError: Cannot read properties of null (reading 'parentNode'),This has been fixed
await nextTick()
// TypeError: Cannot read properties of null (reading 'parentNode')
// This has been fixed
expect(serializeInner(root)).toBe(`<div>sync</div>`)
})

View File

@ -428,8 +428,16 @@ export function updateHOCHostEl(
{ vnode, parent }: ComponentInternalInstance,
el: typeof vnode.el // HostNode
) {
while (parent && parent.subTree === vnode) {
;(vnode = parent.vnode).el = el
parent = parent.parent
while (parent) {
const root = parent.subTree
if (root.suspense && root.suspense.activeBranch === vnode) {
root.el = vnode.el
}
if (root === vnode) {
;(vnode = parent.vnode).el = el
parent = parent.parent
} else {
break
}
}
}

View File

@ -1241,10 +1241,6 @@ function baseCreateRenderer(
if (!initialVNode.el) {
const placeholder = (instance.subTree = createVNode(Comment))
processCommentNode(null, placeholder, container!, anchor)
// This noramlly gets setup by the following `setupRenderEffect`.
// But the call is skipped in initial mounting of async element.
// Thus, manually patching is required here or it will result in a crash during parent component update.
initialVNode.el = placeholder.el
}
return
}