Skip to content

Commit a201092

Browse files
antfuclaude
andauthored
fix: persist async data across tab navigation with custom getCachedData (#963)
Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 741ebeb commit a201092

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

  • packages/devtools/client/composables

packages/devtools/client/composables/utils.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,14 @@ export function parseReadablePath(path: string, root: string) {
8080

8181
export 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

9193
export function getIsMacOS() {

0 commit comments

Comments
 (0)