fix(query): set default query retry to 1 (#5743)

* fix(query): set default query retry to 1

* fix(query): don't retry 404s and limit default retries to 3

* feat: expand status skipping checks

* feat: parallel fetch v2 and v3 in middleware

---------

Co-authored-by: Calum H. (IMB11) <contact@cal.engineer>
This commit is contained in:
Míngxuān Dìng
2026-04-16 19:31:26 +08:00
committed by GitHub
parent 5b5c8c06e3
commit 7b5c746757
2 changed files with 15 additions and 5 deletions

View File

@@ -32,10 +32,11 @@ export default defineNuxtRouteMiddleware(async (to) => {
const projectId = to.params.id as string const projectId = to.params.id as string
try { try {
// Fetch v2 project for redirect check AND cache it for the page // Fetch v2 and v3 in parallel — cache both for the page's useQuery calls
// Using fetchQuery ensures the page's useQuery gets this cached result const [project, projectV3] = await Promise.all([
const project = await queryClient.fetchQuery(projectQueryOptions.v2(projectId, client)) queryClient.fetchQuery(projectQueryOptions.v2(projectId, client)),
const projectV3 = await queryClient.fetchQuery(projectQueryOptions.v3(projectId, client)) queryClient.fetchQuery(projectQueryOptions.v3(projectId, client)),
])
// Let page handle 404 // Let page handle 404
if (!project) return if (!project) return

View File

@@ -8,7 +8,16 @@ export default defineNuxtPlugin((nuxt) => {
const vueQueryState = useState<DehydratedState | null>('vue-query') const vueQueryState = useState<DehydratedState | null>('vue-query')
const queryClient = new QueryClient({ const queryClient = new QueryClient({
defaultOptions: { queries: { staleTime: 10000 } }, defaultOptions: {
queries: {
staleTime: 10000,
retry: (failureCount, error) => {
const status = (error as any)?.statusCode ?? (error as any)?.status
if (status !== undefined && status >= 400 && status < 500 && status !== 429) return false
return failureCount < 3
},
},
},
}) })
const options: VueQueryPluginOptions = { queryClient } const options: VueQueryPluginOptions = { queryClient }