Skip to content

Commit 70ad4ca

Browse files
committed
fix(suspense): fix more suspense patch before resolve edge cases
close #10017
1 parent 972face commit 70ad4ca

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,7 @@ describe('Suspense', () => {
16921692
expect(serializeInner(root)).toBe(`<div>sync</div>`)
16931693
})
16941694

1695-
// #6416 follow up
1695+
// #6416 follow up / #10017
16961696
test('Suspense patched during HOC async component re-mount', async () => {
16971697
const key = ref('k')
16981698
const data = ref('data')
@@ -1713,7 +1713,7 @@ describe('Suspense', () => {
17131713
const App = {
17141714
render() {
17151715
return h(Suspense, null, {
1716-
default: h(Comp, { data: data.value }),
1716+
default: h(Comp, { k: key.value, data: data.value }),
17171717
})
17181718
},
17191719
}

packages/runtime-core/src/componentRenderUtils.ts

-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,6 @@ export function updateHOCHostEl(
428428
{ vnode, parent }: ComponentInternalInstance,
429429
el: typeof vnode.el, // HostNode
430430
) {
431-
if (!el) return
432431
while (parent) {
433432
const root = parent.subTree
434433
if (root.suspense && root.suspense.activeBranch === vnode) {

packages/runtime-core/src/components/Suspense.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,14 @@ export function queueEffectWithSuspense(
864864
function setActiveBranch(suspense: SuspenseBoundary, branch: VNode) {
865865
suspense.activeBranch = branch
866866
const { vnode, parentComponent } = suspense
867-
const el = (vnode.el = branch.el)
867+
let el = branch.el
868+
// if branch has no el after patch, it's a HOC wrapping async components
869+
// drill and locate the placeholder comment node
870+
while (!el && branch.component) {
871+
branch = branch.component.subTree
872+
el = branch.el
873+
}
874+
vnode.el = el
868875
// in case suspense is the root node of a component,
869876
// recursively update the HOC el
870877
if (parentComponent && parentComponent.subTree === vnode) {

0 commit comments

Comments
 (0)