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:
@@ -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
|
||||||
|
|||||||
@@ -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 }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user