fix(nuxt): warn to provide a key for useFetch with transform option (#4590)

This commit is contained in:
Daniel Roe 2022-04-27 17:19:10 +01:00 committed by GitHub
parent 66de7e6c20
commit 7e912e7bf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -141,7 +141,7 @@ export function useAsyncData<
// Client side // Client side
if (process.client) { if (process.client) {
if (fetchOnServer && nuxt.isHydrating) { if (fetchOnServer && nuxt.isHydrating && key in nuxt.payload.data) {
// 1. Hydration (server: true): no fetch // 1. Hydration (server: true): no fetch
asyncData.pending.value = false asyncData.pending.value = false
} else if (instance && (nuxt.isHydrating || options.lazy)) { } else if (instance && (nuxt.isHydrating || options.lazy)) {

View File

@ -28,7 +28,10 @@ export function useFetch<
request: Ref<ReqT> | ReqT | (() => ReqT), request: Ref<ReqT> | ReqT | (() => ReqT),
opts: UseFetchOptions<_ResT, Transform, PickKeys> = {} opts: UseFetchOptions<_ResT, Transform, PickKeys> = {}
) { ) {
const key = '$f_' + (opts.key || hash([request, opts])) if (process.dev && opts.transform && !opts.key) {
console.warn('[nuxt] You should provide a key for `useFetch` when using a custom transform function.')
}
const key = '$f_' + (opts.key || hash([request, { ...opts, transform: null }]))
const _request = computed<FetchRequest>(() => { const _request = computed<FetchRequest>(() => {
let r = request let r = request
if (typeof r === 'function') { if (typeof r === 'function') {