Skip to content

Commit 5d8b43f

Browse files
committed
chore: delay unmount child suspense
1 parent e1399d6 commit 5d8b43f

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

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

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ export interface SuspenseBoundary {
420420
isInFallback: boolean
421421
isHydrating: boolean
422422
isUnmounted: boolean
423+
preEffects: Function[]
423424
effects: Function[]
424425
resolve(force?: boolean, sync?: boolean): void
425426
fallback(fallbackVNode: VNode): void
@@ -500,6 +501,7 @@ function createSuspenseBoundary(
500501
isInFallback: !isHydrating,
501502
isHydrating,
502503
isUnmounted: false,
504+
preEffects: [],
503505
effects: [],
504506

505507
resolve(resume = false, sync = false) {
@@ -520,6 +522,7 @@ function createSuspenseBoundary(
520522
activeBranch,
521523
pendingBranch,
522524
pendingId,
525+
preEffects,
523526
effects,
524527
parentComponent,
525528
container,
@@ -530,6 +533,10 @@ function createSuspenseBoundary(
530533
if (suspense.isHydrating) {
531534
suspense.isHydrating = false
532535
} else if (!resume) {
536+
if (preEffects) {
537+
preEffects.forEach(e => e())
538+
preEffects.length = 0
539+
}
533540
delayEnter =
534541
activeBranch &&
535542
pendingBranch!.transition &&
@@ -735,25 +742,29 @@ function createSuspenseBoundary(
735742
},
736743

737744
unmount(parentSuspense, doRemove) {
738-
if (parentSuspense && parentSuspense.deps > 0) {
739-
return
740-
}
741-
suspense.isUnmounted = true
742-
if (suspense.activeBranch) {
743-
unmount(
744-
suspense.activeBranch,
745-
parentComponent,
746-
parentSuspense,
747-
doRemove,
748-
)
745+
const performUnmount = () => {
746+
suspense.isUnmounted = true
747+
if (suspense.activeBranch) {
748+
unmount(
749+
suspense.activeBranch,
750+
parentComponent,
751+
parentSuspense,
752+
doRemove,
753+
)
754+
}
755+
if (suspense.pendingBranch) {
756+
unmount(
757+
suspense.pendingBranch,
758+
parentComponent,
759+
parentSuspense,
760+
doRemove,
761+
)
762+
}
749763
}
750-
if (suspense.pendingBranch) {
751-
unmount(
752-
suspense.pendingBranch,
753-
parentComponent,
754-
parentSuspense,
755-
doRemove,
756-
)
764+
if (parentSuspense && parentSuspense.deps > 0) {
765+
parentSuspense.preEffects.push(performUnmount)
766+
} else {
767+
performUnmount()
757768
}
758769
},
759770
}

0 commit comments

Comments
 (0)