Skip to content

dx(runtime-core): warning for no suspense boundary #3657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/runtime-core/__tests__/components/Suspense.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1125,4 +1125,23 @@ describe('Suspense', () => {
await nextTick()
expect(serializeInner(root)).toBe(`<div>parent<!----></div>`)
})

test('warning for no suspense boundary', async () => {
const Comp = {
async setup() {
return () => h('div', 'child')
}
}
const App = {
setup() {
return () => h(Comp)
}
}

render(h(App), nodeOps.createElement('div'))
expect(
`setup() returned a Promise, but there is no suspense boundary to handle it, ` +
`use the <Suspense> component to create a suspense boundary.`
).toHaveBeenWarnedLast()
})
})
6 changes: 6 additions & 0 deletions packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,12 @@ function setupStatefulComponent(
// async setup returned Promise.
// bail here and wait for re-entry.
instance.asyncDep = setupResult
if (__DEV__ && !instance.suspense) {
warn(
`setup() returned a Promise, but there is no suspense boundary to handle it, ` +
`use the <Suspense> component to create a suspense boundary.`
)
}
} else if (__DEV__) {
warn(
`setup() returned a Promise, but the version of Vue you are using ` +
Expand Down