Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxt)!: remove initialCache option #8885

Merged
merged 3 commits into from Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/content/3.api/1.composables/use-fetch.md
Expand Up @@ -27,7 +27,6 @@ type UseFetchOptions = {
transform?: (input: DataT) => DataT
pick?: string[]
watch?: WatchSource[]
initialCache?: boolean
}

type AsyncData<DataT> = {
Expand Down Expand Up @@ -60,7 +59,6 @@ All fetch options can be given a `computed` or `ref` value. These will be watche
* `default`: A factory function to set the default value of the data, before the async function resolves - particularly useful with the `lazy: true` option.
* `pick`: Only pick specified keys in this array from the `handler` function result.
* `watch`: watch reactive sources to auto-refresh.
* `initialCache`: When set to `false`, will skip payload cache for initial fetch (defaults to `true`).
* `transform`: A function that can be used to alter `handler` function result after resolving.
* `immediate`: When set to `false`, will prevent the request from firing immediately. (defaults to `true`)

Expand Down
10 changes: 4 additions & 6 deletions packages/nuxt/src/app/composables/asyncData.ts
Expand Up @@ -29,7 +29,6 @@ export interface AsyncDataOptions<
transform?: Transform
pick?: PickKeys
watch?: MultiWatchSources
initialCache?: boolean
immediate?: boolean
}

Expand Down Expand Up @@ -102,19 +101,18 @@ export function useAsyncData<
console.warn('[useAsyncData] `defer` has been renamed to `lazy`. Support for `defer` will be removed in RC.')
}
options.lazy = options.lazy ?? (options as any).defer ?? false
options.initialCache = options.initialCache ?? true
options.immediate = options.immediate ?? true

// Setup nuxt instance payload
const nuxt = useNuxtApp()

const useInitialCache = () => (nuxt.isHydrating || options.initialCache) && nuxt.payload.data[key] !== undefined
const usePayloadData = () => nuxt.isHydrating && nuxt.payload.data[key] !== undefined

// Create or use a shared asyncData entity
if (!nuxt._asyncData[key]) {
nuxt._asyncData[key] = {
data: ref(useInitialCache() ? nuxt.payload.data[key] : options.default?.() ?? null),
pending: ref(!useInitialCache()),
data: ref(usePayloadData() ? nuxt.payload.data[key] : options.default?.() ?? null),
pending: ref(!usePayloadData()),
error: ref(nuxt.payload._errors[key] ? createError(nuxt.payload._errors[key]) : null)
}
}
Expand All @@ -130,7 +128,7 @@ export function useAsyncData<
(nuxt._asyncDataPromises[key] as any).cancelled = true
}
// Avoid fetching same key that is already fetched
if (opts._initial && useInitialCache()) {
if (opts._initial && usePayloadData()) {
return nuxt.payload.data[key]
}
asyncData.pending.value = true
Expand Down
2 changes: 0 additions & 2 deletions packages/nuxt/src/app/composables/fetch.ts
Expand Up @@ -68,7 +68,6 @@ export function useFetch<
transform,
pick,
watch,
initialCache,
immediate,
...fetchOptions
} = opts
Expand All @@ -84,7 +83,6 @@ export function useFetch<
default: defaultFn,
transform,
pick,
initialCache,
immediate,
watch: [
_fetchOptions,
Expand Down