File tree 2 files changed +37
-6
lines changed
2 files changed +37
-6
lines changed Original file line number Diff line number Diff line change @@ -1093,4 +1093,36 @@ describe('Suspense', () => {
1093
1093
await nextTick ( )
1094
1094
expect ( root . innerHTML ) . toBe ( `<div><span>2</span></div>` )
1095
1095
} )
1096
+
1097
+ // #2215
1098
+ test ( 'toggling nested async setup component inside already resolved suspense' , async ( ) => {
1099
+ const toggle = ref ( false )
1100
+ const Child = {
1101
+ async setup ( ) {
1102
+ return ( ) => h ( 'div' , 'child' )
1103
+ }
1104
+ }
1105
+ const Parent = ( ) => h ( 'div' , [ 'parent' , toggle . value ? h ( Child ) : null ] )
1106
+ const Comp = {
1107
+ setup ( ) {
1108
+ return ( ) => h ( Suspense , ( ) => h ( Parent ) )
1109
+ }
1110
+ }
1111
+
1112
+ const root = nodeOps . createElement ( 'div' )
1113
+ render ( h ( Comp ) , root )
1114
+ expect ( serializeInner ( root ) ) . toBe ( `<div>parent<!----></div>` )
1115
+
1116
+ toggle . value = true
1117
+ // wait for flush
1118
+ await nextTick ( )
1119
+ // wait for child async setup resolve
1120
+ await nextTick ( )
1121
+ // child should be rendered now instead of stuck in limbo
1122
+ expect ( serializeInner ( root ) ) . toBe ( `<div>parent<div>child</div></div>` )
1123
+
1124
+ toggle . value = false
1125
+ await nextTick ( )
1126
+ expect ( serializeInner ( root ) ) . toBe ( `<div>parent<!----></div>` )
1127
+ } )
1096
1128
} )
Original file line number Diff line number Diff line change @@ -542,12 +542,11 @@ function createSuspenseBoundary(
542
542
} ,
543
543
544
544
registerDep ( instance , setupRenderEffect ) {
545
- if ( ! suspense . pendingBranch ) {
546
- return
545
+ const isInPendingSuspense = ! ! suspense . pendingBranch
546
+ if ( isInPendingSuspense ) {
547
+ suspense . deps ++
547
548
}
548
-
549
549
const hydratedEl = instance . vnode . el
550
- suspense . deps ++
551
550
instance
552
551
. asyncDep ! . catch ( err => {
553
552
handleError ( err , instance , ErrorCodes . SETUP_FUNCTION )
@@ -562,7 +561,6 @@ function createSuspenseBoundary(
562
561
) {
563
562
return
564
563
}
565
- suspense . deps --
566
564
// retry from this component
567
565
instance . asyncResolved = true
568
566
const { vnode } = instance
@@ -597,7 +595,8 @@ function createSuspenseBoundary(
597
595
if ( __DEV__ ) {
598
596
popWarningContext ( )
599
597
}
600
- if ( suspense . deps === 0 ) {
598
+ // only decrease deps count if suspense is not already resolved
599
+ if ( isInPendingSuspense && -- suspense . deps === 0 ) {
601
600
suspense . resolve ( )
602
601
}
603
602
} )
You can’t perform that action at this time.
0 commit comments