This repository was archived by the owner on Apr 6, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -114,11 +114,16 @@ export function useAsyncData<
114114
115115 const useInitialCache = ( ) => ( nuxt . isHydrating || options . initialCache ) && nuxt . payload . data [ key ] !== undefined
116116
117- const asyncData = {
118- data : ref ( useInitialCache ( ) ? nuxt . payload . data [ key ] : options . default ?.( ) ?? null ) ,
119- pending : ref ( ! useInitialCache ( ) ) ,
120- error : ref ( nuxt . payload . _errors [ key ] ?? null )
121- } as AsyncData < DataT , DataE >
117+ // Create or use a shared asyncData entity
118+ if ( ! nuxt . _asyncData [ key ] ) {
119+ nuxt . _asyncData [ key ] = {
120+ data : ref ( useInitialCache ( ) ? nuxt . payload . data [ key ] : options . default ?.( ) ?? null ) ,
121+ pending : ref ( ! useInitialCache ( ) ) ,
122+ error : ref ( nuxt . payload . _errors [ key ] ?? null )
123+ }
124+ }
125+ // TODO: Else, Soemhow check for confliciting keys with different defaults or fetcher
126+ const asyncData = { ...nuxt . _asyncData [ key ] } as AsyncData < DataT , DataE >
122127
123128 asyncData . refresh = ( opts = { } ) => {
124129 // Avoid fetching same key more than once at a time
Original file line number Diff line number Diff line change 11/* eslint-disable no-use-before-define */
2- import { getCurrentInstance , reactive } from 'vue'
2+ import { getCurrentInstance , reactive , Ref } from 'vue'
33import type { App , onErrorCaptured , VNode } from 'vue'
44import { createHooks , Hookable } from 'hookable'
55import type { RuntimeConfig , AppConfigInput } from '@nuxt/schema'
@@ -66,6 +66,11 @@ interface _NuxtApp {
6666 [ key : string ] : any
6767
6868 _asyncDataPromises : Record < string , Promise < any > | undefined >
69+ _asyncData : Record < string , {
70+ data : Ref < any >
71+ pending : Ref < boolean >
72+ error : Ref < any >
73+ } > ,
6974
7075 ssrContext ?: NuxtSSRContext
7176 payload : {
@@ -113,6 +118,7 @@ export function createNuxtApp (options: CreateOptions) {
113118 } ) ,
114119 isHydrating : process . client ,
115120 _asyncDataPromises : { } ,
121+ _asyncData : { } ,
116122 ...options
117123 } as any as NuxtApp
118124
You can’t perform that action at this time.
0 commit comments