mirror of
https://github.com/nuxt/nuxt.git
synced 2025-03-21 16:55:57 +00:00
feat(nuxt): show source file when warning about undefined useAsyncData (#31144)
This commit is contained in:
parent
0a69213358
commit
c398ce2817
@ -206,6 +206,7 @@ export default createConfigForNuxt({
|
||||
'ohash/utils',
|
||||
'pathe',
|
||||
'uncrypto',
|
||||
'errx', /* only used in dev */
|
||||
// internal deps
|
||||
'nuxt/app',
|
||||
].map(r => `!${r}`),
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { computed, getCurrentInstance, getCurrentScope, onBeforeMount, onScopeDispose, onServerPrefetch, onUnmounted, ref, shallowRef, toRef, unref, watch } from 'vue'
|
||||
import type { MultiWatchSources, Ref } from 'vue'
|
||||
import { captureStackTrace } from 'errx'
|
||||
import type { NuxtApp } from '../nuxt'
|
||||
import { useNuxtApp } from '../nuxt'
|
||||
import { toArray } from '../utils'
|
||||
@ -301,8 +302,11 @@ export function useAsyncData<
|
||||
}
|
||||
|
||||
if (import.meta.dev && import.meta.server && typeof result === 'undefined') {
|
||||
const stack = captureStackTrace()
|
||||
const { source, line, column } = stack[stack.length - 1] ?? {}
|
||||
const explanation = source ? ` (used at ${source.replace(/^file:\/\//, '')}:${line}:${column})` : ''
|
||||
// @ts-expect-error private property
|
||||
console.warn(`[nuxt] \`${options._functionName || 'useAsyncData'}\` must return a value (it should not be \`undefined\`) or the request may be duplicated on the client side.`)
|
||||
console.warn(`[nuxt] \`${options._functionName || 'useAsyncData'}${explanation}\` must return a value (it should not be \`undefined\`) or the request may be duplicated on the client side.`)
|
||||
}
|
||||
|
||||
nuxtApp.payload.data[key] = result
|
||||
|
Loading…
Reference in New Issue
Block a user