Skip to content

Commit

Permalink
fix(Suspense): properly fix #6416
Browse files Browse the repository at this point in the history
previous fix caused regressions in nuxt
  • Loading branch information
yyx990803 committed Dec 13, 2023
1 parent 33159a5 commit 0db336f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 3 additions & 1 deletion packages/runtime-core/__tests__/components/Suspense.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>`)
})

Expand Down
14 changes: 11 additions & 3 deletions packages/runtime-core/src/componentRenderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
4 changes: 0 additions & 4 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

This comment has been minimized.

Copy link
@mmis1000

mmis1000 Dec 14, 2023

Contributor

This change seems regressed a case fixed in #7290
The crash of this playground happened again when selecting 3.4.0-beta.2

Is this accidentally removed? Or is this case not covered by accident?

This comment has been minimized.

Copy link
@mmis1000

mmis1000 Dec 15, 2023

Contributor

@yyx990803
(I am not sure if github send notification to commit owner or not, so tag just in case.)

This comment has been minimized.

Copy link
@yyx990803

yyx990803 Dec 15, 2023

Author Member

This line is causing a few regressions for Nuxt in ecosystem-ci, when HMR and SSR are combined. I'm investigating your new repro case.

This comment has been minimized.

Copy link
@yyx990803

yyx990803 Dec 15, 2023

Author Member

fixed in f0f6f7c

}
return
}
Expand Down

0 comments on commit 0db336f

Please sign in to comment.