Skip to content

Commit 0db336f

Browse files
committed
fix(Suspense): properly fix #6416
previous fix caused regressions in nuxt
1 parent 33159a5 commit 0db336f

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

packages/runtime-core/__tests__/components/Suspense.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,9 @@ describe('Suspense', () => {
16841684
expect(serializeInner(root)).toBe('<div>async</div>')
16851685

16861686
viewRef.value = 1
1687-
await nextTick() //TypeError: Cannot read properties of null (reading 'parentNode'),This has been fixed
1687+
await nextTick()
1688+
// TypeError: Cannot read properties of null (reading 'parentNode')
1689+
// This has been fixed
16881690
expect(serializeInner(root)).toBe(`<div>sync</div>`)
16891691
})
16901692

packages/runtime-core/src/componentRenderUtils.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,16 @@ export function updateHOCHostEl(
428428
{ vnode, parent }: ComponentInternalInstance,
429429
el: typeof vnode.el // HostNode
430430
) {
431-
while (parent && parent.subTree === vnode) {
432-
;(vnode = parent.vnode).el = el
433-
parent = parent.parent
431+
while (parent) {
432+
const root = parent.subTree
433+
if (root.suspense && root.suspense.activeBranch === vnode) {
434+
root.el = vnode.el
435+
}
436+
if (root === vnode) {
437+
;(vnode = parent.vnode).el = el
438+
parent = parent.parent
439+
} else {
440+
break
441+
}
434442
}
435443
}

packages/runtime-core/src/renderer.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,10 +1241,6 @@ function baseCreateRenderer(
12411241
if (!initialVNode.el) {
12421242
const placeholder = (instance.subTree = createVNode(Comment))
12431243
processCommentNode(null, placeholder, container!, anchor)
1244-
// This noramlly gets setup by the following `setupRenderEffect`.
1245-
// But the call is skipped in initial mounting of async element.
1246-
// Thus, manually patching is required here or it will result in a crash during parent component update.
1247-
initialVNode.el = placeholder.el
12481244
}
12491245
return
12501246
}

0 commit comments

Comments
 (0)