Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
fix: cancel pending promises when clearing data
  • Loading branch information
danielroe committed Mar 16, 2024
commit 61c91135401ea12a0dccc947daadb43201d0dcb3
14 changes: 8 additions & 6 deletions packages/nuxt/src/app/composables/asyncData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ export function useAsyncData<
if (value) { return value as Promise<ResT> }

const promise = nuxtApp.runWithContext(_handler)
nuxtApp.ssrContext!._sharedPrerenderCache!.set(key, promise)
return promise

nuxtApp.ssrContext!._sharedPrerenderCache!.set(key, promise)
return promise
}

// Used to get default values
Expand Down Expand Up @@ -516,10 +517,11 @@ function clearNuxtDataByKey (nuxtApp: NuxtApp, key: string): void {
}

if (nuxtApp._asyncData[key]) {
nuxtApp._asyncData[key]!.data.value = undefined
nuxtApp._asyncData[key]!.error.value = null
nuxtApp._asyncData[key]!.pending.value = false
nuxtApp._asyncData[key]!.status.value = 'idle'
(nuxtApp._asyncDataPromises[key] as any).cancelled = true
nuxtApp._asyncData[key]!.data.value = undefined
nuxtApp._asyncData[key]!.error.value = null
nuxtApp._asyncData[key]!.pending.value = false
nuxtApp._asyncData[key]!.status.value = 'idle'
}

if (key in nuxtApp._asyncDataPromises) {
Expand Down