diff --git a/docs/content/1.getting-started/6.data-fetching.md b/docs/content/1.getting-started/6.data-fetching.md index 5bc3086b6f3..f99e29a5913 100644 --- a/docs/content/1.getting-started/6.data-fetching.md +++ b/docs/content/1.getting-started/6.data-fetching.md @@ -152,10 +152,10 @@ function next() { The key to making this work is to call the `refresh()` method returned from the `useFetch()` composable when a query parameter has changed. -By default, `refresh()` will not make a new request if one is already pending. You can override any pending requests with the override option. Previous requests will not be cancelled, but their result will not update the data or pending state - and any previously awaited promises will not resolve until this new request resolves. +By default, `refresh()` will cancel any pending requests; their result will not update the data or pending state. Any previously awaited promises will not resolve until this new request resolves. You can prevent this behaviour by setting the `dedupe` option, which will instead return the promise for the currently-executing request, if there is one. ```js -refresh({ override: true }) +refresh({ dedupe: true }) ``` ### `refreshNuxtData` diff --git a/docs/content/3.api/1.composables/use-async-data.md b/docs/content/3.api/1.composables/use-async-data.md index bdb6a8c1dbf..29825ec5104 100644 --- a/docs/content/3.api/1.composables/use-async-data.md +++ b/docs/content/3.api/1.composables/use-async-data.md @@ -30,7 +30,7 @@ type AsyncDataOptions = { } interface RefreshOptions { - override?: boolean + dedupe?: boolean } type AsyncData = { diff --git a/docs/content/3.api/1.composables/use-fetch.md b/docs/content/3.api/1.composables/use-fetch.md index a40aafba38a..6e2148c0eb8 100644 --- a/docs/content/3.api/1.composables/use-fetch.md +++ b/docs/content/3.api/1.composables/use-fetch.md @@ -32,7 +32,7 @@ type UseFetchOptions = { type AsyncData = { data: Ref pending: Ref - refresh: (opts?: { override?: boolean }) => Promise + refresh: (opts?: { dedupe?: boolean }) => Promise execute: () => Promise error: Ref } diff --git a/packages/nuxt/src/app/composables/asyncData.ts b/packages/nuxt/src/app/composables/asyncData.ts index 5fe425d11ca..28a79a2df24 100644 --- a/packages/nuxt/src/app/composables/asyncData.ts +++ b/packages/nuxt/src/app/composables/asyncData.ts @@ -39,7 +39,7 @@ export interface AsyncDataExecuteOptions { * not be cancelled, but their result will not affect the data/pending state - and any * previously awaited promises will not resolve until this new request resolves. */ - override?: boolean + dedupe?: boolean } export interface _AsyncData { @@ -122,7 +122,7 @@ export function useAsyncData< asyncData.refresh = asyncData.execute = (opts = {}) => { if (nuxt._asyncDataPromises[key]) { - if (!opts.override) { + if (opts.dedupe === false) { // Avoid fetching same key more than once at a time return nuxt._asyncDataPromises[key] } diff --git a/test/fixtures/basic/pages/useAsyncData/override.vue b/test/fixtures/basic/pages/useAsyncData/override.vue index 82d69866733..3d0328c43ec 100644 --- a/test/fixtures/basic/pages/useAsyncData/override.vue +++ b/test/fixtures/basic/pages/useAsyncData/override.vue @@ -15,14 +15,14 @@ if (count || data.value !== 1) { } timeout = 100 -const p = refresh() +const p = refresh({ dedupe: true }) if (process.client && (count !== 0 || data.value !== 1)) { throw new Error('count should start at 0') } timeout = 0 -await refresh({ override: true }) +await refresh() if (process.client && (count !== 1 || data.value !== 1)) { throw new Error('override should execute')