@@ -247,17 +247,20 @@ export function useAsyncData<
247247 }
248248
249249 // Create or use a shared asyncData entity
250- const initialFetchOptions : AsyncDataExecuteOptions = { cause : 'initial' , dedupe : options . dedupe }
251- if ( ! nuxtApp . _asyncData [ key . value ] ?. _init ) {
252- initialFetchOptions . cachedData = options . getCachedData ! ( key . value , nuxtApp , { cause : 'initial' } )
253- nuxtApp . _asyncData [ key . value ] = createAsyncData ( nuxtApp , key . value , _handler , options , initialFetchOptions . cachedData )
250+ function createInitialFetch ( ) {
251+ const initialFetchOptions : AsyncDataExecuteOptions = { cause : 'initial' , dedupe : options . dedupe }
252+ if ( ! nuxtApp . _asyncData [ key . value ] ?. _init ) {
253+ initialFetchOptions . cachedData = options . getCachedData ! ( key . value , nuxtApp , { cause : 'initial' } )
254+ nuxtApp . _asyncData [ key . value ] = createAsyncData ( nuxtApp , key . value , _handler , options , initialFetchOptions . cachedData )
255+ }
256+ return ( ) => nuxtApp . _asyncData [ key . value ] ! . execute ( initialFetchOptions )
254257 }
258+
259+ const initialFetch = createInitialFetch ( )
255260 const asyncData = nuxtApp . _asyncData [ key . value ] !
256261
257262 asyncData . _deps ++
258263
259- const initialFetch = ( ) => nuxtApp . _asyncData [ key . value ] ! . execute ( initialFetchOptions )
260-
261264 const fetchOnServer = options . server !== false && nuxtApp . payload . serverRendered
262265
263266 // Server side
@@ -389,8 +392,14 @@ export function useAsyncData<
389392 pending : writableComputedRef ( ( ) => nuxtApp . _asyncData [ key . value ] ?. pending as Ref < boolean > ) ,
390393 status : writableComputedRef ( ( ) => nuxtApp . _asyncData [ key . value ] ?. status as Ref < AsyncDataRequestStatus > ) ,
391394 error : writableComputedRef ( ( ) => nuxtApp . _asyncData [ key . value ] ?. error as Ref < NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError < NuxtErrorDataT > > ) ,
392- refresh : ( ...args ) => nuxtApp . _asyncData [ key . value ] ! . execute ( ...args ) ,
393- execute : ( ...args ) => nuxtApp . _asyncData [ key . value ] ! . execute ( ...args ) ,
395+ refresh : ( ...args ) => {
396+ if ( ! nuxtApp . _asyncData [ key . value ] ?. _init ) {
397+ const initialFetch = createInitialFetch ( )
398+ return initialFetch ( )
399+ }
400+ return nuxtApp . _asyncData [ key . value ] ! . execute ( ...args )
401+ } ,
402+ execute : ( ...args ) => asyncReturn . refresh ( ...args ) ,
394403 clear : ( ) => clearNuxtDataByKey ( nuxtApp , key . value ) ,
395404 }
396405
0 commit comments