fix(nuxt): deprecate boolean values for dedupe (#25334)

This commit is contained in:
Alexander Lichter 2024-01-20 00:50:16 +01:00 committed by GitHub
parent 90d8518c84
commit 9d1ca7cd88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -92,7 +92,7 @@ export interface AsyncDataOptions<
export interface AsyncDataExecuteOptions { export interface AsyncDataExecuteOptions {
_initial?: boolean _initial?: boolean
// TODO: deprecate boolean option in future minor // TODO: remove boolean option in Nuxt 4
/** /**
* Force a refresh, even if there is already a pending request. Previous requests will * Force a refresh, even if there is already a pending request. Previous requests will
* not be cancelled, but their result will not affect the data/pending state - and any * not be cancelled, but their result will not affect the data/pending state - and any
@ -115,7 +115,7 @@ export interface _AsyncData<DataT, ErrorT> {
export type AsyncData<Data, Error> = _AsyncData<Data, Error> & Promise<_AsyncData<Data, Error>> export type AsyncData<Data, Error> = _AsyncData<Data, Error> & Promise<_AsyncData<Data, Error>>
// TODO: deprecate boolean option in future minor // TODO: remove boolean option in Nuxt 4
const isDefer = (dedupe?: boolean | 'cancel' | 'defer') => dedupe === 'defer' || dedupe === false const isDefer = (dedupe?: boolean | 'cancel' | 'defer') => dedupe === 'defer' || dedupe === false
/** /**
@ -235,6 +235,10 @@ export function useAsyncData<
options.deep = options.deep ?? asyncDataDefaults.deep options.deep = options.deep ?? asyncDataDefaults.deep
options.dedupe = options.dedupe ?? 'cancel' options.dedupe = options.dedupe ?? 'cancel'
if (import.meta.dev && typeof options.dedupe === 'boolean') {
console.warn('[nuxt] `boolean` values are deprecated for the `dedupe` option of `useAsyncData` and will be removed in the future. Use \'cancel\' or \'defer\' instead.')
}
const hasCachedData = () => ![null, undefined].includes(options.getCachedData!(key) as any) const hasCachedData = () => ![null, undefined].includes(options.getCachedData!(key) as any)
// Create or use a shared asyncData entity // Create or use a shared asyncData entity