Skip to content

Commit

Permalink
fix: correctly track new define queries when switching pages
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Feb 6, 2025
1 parent bf7ef2f commit f9eeec1
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/query-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,19 @@ export const useQueryCache = /* @__PURE__ */ defineStore(QUERY_STORE_ID, ({ acti
} else {
// if the entry already exists, we know the queries inside
// we should consider as if they are activated again
for (const queryEntry of defineQueryEntry[0]) {
if (queryEntry.options?.refetchOnMount && toValue(queryEntry.options.enabled)) {
if (toValue(queryEntry.options.refetchOnMount) === 'always') {
fetch(queryEntry)
defineQueryEntry[0] = defineQueryEntry[0].map((oldEntry) => {
// the entries' key might have change (e.g. Nuxt navigation)
// so we need to ensure them again
const entry = oldEntry.options ? ensure(oldEntry.options, oldEntry) : oldEntry
if (entry.options?.refetchOnMount && toValue(entry.options.enabled)) {
if (toValue(entry.options.refetchOnMount) === 'always') {
fetch(entry)
} else {
refresh(queryEntry)
refresh(entry)
}
}
}
return entry
})
}

return defineQueryEntry
Expand All @@ -371,7 +375,10 @@ export const useQueryCache = /* @__PURE__ */ defineStore(QUERY_STORE_ID, ({ acti
) {
if (!effect) return
entry.deps.add(effect)
// clearTimeout ignores anything that isn't a timerId
clearTimeout(entry.gcTimeout)
entry.gcTimeout = undefined
triggerCache()
}

function untrack(
Expand Down

0 comments on commit f9eeec1

Please sign in to comment.