Skip to content

Commit cc5dab2

Browse files
committed
chore: delay unmount child suspense
1 parent e8aed9e commit cc5dab2

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

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

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,9 @@ function createSuspenseBoundary(
521521
if (suspense.isHydrating) {
522522
suspense.isHydrating = false
523523
} else if (!resume) {
524-
if (preEffects) {
524+
if (preEffects.length) {
525525
preEffects.forEach(e => e())
526-
preEffects.length = 0
526+
suspense.preEffects = []
527527
}
528528
delayEnter =
529529
activeBranch &&
@@ -730,29 +730,22 @@ function createSuspenseBoundary(
730730
},
731731

732732
unmount(parentSuspense, doRemove) {
733-
const performUnmount = () => {
734-
suspense.isUnmounted = true
735-
if (suspense.activeBranch) {
736-
unmount(
737-
suspense.activeBranch,
738-
parentComponent,
739-
parentSuspense,
740-
doRemove,
741-
)
742-
}
743-
if (suspense.pendingBranch) {
744-
unmount(
745-
suspense.pendingBranch,
746-
parentComponent,
747-
parentSuspense,
748-
doRemove,
749-
)
750-
}
733+
suspense.isUnmounted = true
734+
if (suspense.activeBranch) {
735+
unmount(
736+
suspense.activeBranch,
737+
parentComponent,
738+
parentSuspense,
739+
doRemove,
740+
)
751741
}
752-
if (parentSuspense && parentSuspense.deps > 0) {
753-
parentSuspense.preEffects.push(performUnmount)
754-
} else {
755-
performUnmount()
742+
if (suspense.pendingBranch) {
743+
unmount(
744+
suspense.pendingBranch,
745+
parentComponent,
746+
parentSuspense,
747+
doRemove,
748+
)
756749
}
757750
},
758751
}

packages/runtime-core/src/renderer.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,13 @@ function baseCreateRenderer(
21342134
unmountComponent(vnode.component!, parentSuspense, doRemove)
21352135
} else {
21362136
if (__FEATURE_SUSPENSE__ && shapeFlag & ShapeFlags.SUSPENSE) {
2137-
vnode.suspense!.unmount(parentSuspense, doRemove)
2137+
if (parentSuspense && parentSuspense.deps > 0) {
2138+
parentSuspense.preEffects.push(() => {
2139+
vnode.suspense!.unmount(parentSuspense, doRemove)
2140+
})
2141+
} else {
2142+
vnode.suspense!.unmount(parentSuspense, doRemove)
2143+
}
21382144
return
21392145
}
21402146

@@ -2175,7 +2181,13 @@ function baseCreateRenderer(
21752181
}
21762182

21772183
if (doRemove) {
2178-
remove(vnode)
2184+
if (parentSuspense && parentSuspense.deps > 0) {
2185+
parentSuspense.preEffects.push(() => {
2186+
remove(vnode)
2187+
})
2188+
} else {
2189+
remove(vnode)
2190+
}
21792191
}
21802192
}
21812193

0 commit comments

Comments
 (0)