<div v-if="errorMessage">{{ errorMessage }}</div>
<Suspense v-else>
<div>
- <Async />
+ <Async />
</div>
<template #fallback>
<div>fallback</div>
await nextTick()
expect(serializeInner(root)).toBe(`<div>parent<!----></div>`)
})
+
+ test('warn if using async setup when not in a Suspense boundary', () => {
+ const Child = {
+ name: 'Child',
+ async setup() {
+ return () => h('div', 'child')
+ }
+ }
+ const Parent = {
+ setup() {
+ return () => h('div', [h(Child)])
+ }
+ }
+
+ const root = nodeOps.createElement('div')
+ render(h(Parent), root)
+
+ expect(
+ `A component with async setup() must be nested in a <Suspense>`
+ ).toHaveBeenWarned()
+ })
})
if (isPromise(setupResult)) {
setupResult.then(unsetCurrentInstance, unsetCurrentInstance)
-
if (isSSR) {
// return the promise so server-renderer can wait on it
return setupResult
// async setup returned Promise.
// bail here and wait for re-entry.
instance.asyncDep = setupResult
+ if (__DEV__ && !instance.suspense) {
+ const name = Component.name ?? 'Anonymous'
+ warn(
+ `Component <${name}>: setup function returned a promise, but no ` +
+ `<Suspense> boundary was found in the parent component tree. ` +
+ `A component with async setup() must be nested in a <Suspense> ` +
+ `in order to be rendered.`
+ )
+ }
} else if (__DEV__) {
warn(
`setup() returned a Promise, but the version of Vue you are using ` +