Skip to content

Commit 3e7bb7d

Browse files
committed
feat(runtime-core): warn async data()
1 parent 78977c3 commit 3e7bb7d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/runtime-core/src/componentOptions.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
isArray,
1616
EMPTY_OBJ,
1717
NOOP,
18-
hasOwn
18+
hasOwn,
19+
isPromise
1920
} from '@vue/shared'
2021
import { computed } from './apiComputed'
2122
import { watch, WatchOptions, WatchCallback } from './apiWatch'
@@ -316,6 +317,13 @@ export function applyOptions(
316317
)
317318
}
318319
const data = dataOptions.call(ctx, ctx)
320+
if (__DEV__ && isPromise(data)) {
321+
warn(
322+
`data() returned a Promise - note data() cannot be async; If you ` +
323+
`intend to perform data fetching before component renders, use ` +
324+
`async setup() + <Suspense>.`
325+
)
326+
}
319327
if (!isObject(data)) {
320328
__DEV__ && warn(`data() should return an object.`)
321329
} else if (instance.data === EMPTY_OBJ) {

0 commit comments

Comments
 (0)