File tree Expand file tree Collapse file tree
packages/devtools/client/composables Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -80,12 +80,14 @@ export function parseReadablePath(path: string, root: string) {
8080
8181export function useAsyncState < T > ( key : string , fn : ( ) => Promise < T > , options ?: AsyncDataOptions < T > ) {
8282 const nuxt = useNuxtApp ( )
83-
84- const unique = nuxt . payload . unique = nuxt . payload . unique || { } as any
85- if ( ! unique [ key ] )
86- unique [ key ] = useAsyncData ( key , fn , options )
87-
88- return unique [ key ] . data as Ref < T | null >
83+ const { data } = useAsyncData ( key , fn , {
84+ ...options ,
85+ // Custom getCachedData serves two purposes:
86+ // 1. Returns previously fetched data from payload.data on remount, so pages render instantly
87+ // 2. Prevents Nuxt's purgeCachedData from clearing data when the last consumer unmounts
88+ getCachedData : key => nuxt . payload . data [ key ] as T ,
89+ } )
90+ return data as Ref < T | null >
8991}
9092
9193export function getIsMacOS ( ) {
You can’t perform that action at this time.
0 commit comments