File tree 2 files changed +31
-2
lines changed
2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -709,7 +709,7 @@ describe('Suspense', () => {
709
709
<div v-if="errorMessage">{{ errorMessage }}</div>
710
710
<Suspense v-else>
711
711
<div>
712
- <Async />
712
+ <Async />
713
713
</div>
714
714
<template #fallback>
715
715
<div>fallback</div>
@@ -1232,4 +1232,25 @@ describe('Suspense', () => {
1232
1232
await nextTick ( )
1233
1233
expect ( serializeInner ( root ) ) . toBe ( `<div>parent<!----></div>` )
1234
1234
} )
1235
+
1236
+ test ( 'warn if using async setup when not in a Suspense boundary' , ( ) => {
1237
+ const Child = {
1238
+ name : 'Child' ,
1239
+ async setup ( ) {
1240
+ return ( ) => h ( 'div' , 'child' )
1241
+ }
1242
+ }
1243
+ const Parent = {
1244
+ setup ( ) {
1245
+ return ( ) => h ( 'div' , [ h ( Child ) ] )
1246
+ }
1247
+ }
1248
+
1249
+ const root = nodeOps . createElement ( 'div' )
1250
+ render ( h ( Parent ) , root )
1251
+
1252
+ expect (
1253
+ `A component with async setup() must be nested in a <Suspense>`
1254
+ ) . toHaveBeenWarned ( )
1255
+ } )
1235
1256
} )
Original file line number Diff line number Diff line change @@ -654,7 +654,6 @@ function setupStatefulComponent(
654
654
655
655
if ( isPromise ( setupResult ) ) {
656
656
setupResult . then ( unsetCurrentInstance , unsetCurrentInstance )
657
-
658
657
if ( isSSR ) {
659
658
// return the promise so server-renderer can wait on it
660
659
return setupResult
@@ -668,6 +667,15 @@ function setupStatefulComponent(
668
667
// async setup returned Promise.
669
668
// bail here and wait for re-entry.
670
669
instance . asyncDep = setupResult
670
+ if ( __DEV__ && ! instance . suspense ) {
671
+ const name = Component . name ?? 'Anonymous'
672
+ warn (
673
+ `Component <${ name } >: setup function returned a promise, but no ` +
674
+ `<Suspense> boundary was found in the parent component tree. ` +
675
+ `A component with async setup() must be nested in a <Suspense> ` +
676
+ `in order to be rendered.`
677
+ )
678
+ }
671
679
} else if ( __DEV__ ) {
672
680
warn (
673
681
`setup() returned a Promise, but the version of Vue you are using ` +
You can’t perform that action at this time.
0 commit comments