From b993a0a8315b06626baac8d56033ccace4c99def Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Fri, 3 Apr 2026 18:28:04 +0200 Subject: [PATCH] fix: skip retries on 404 for single-resource queries Prevents 10-second loading skeleton when navigating to non-existent threads, setups, or items. Shows error/not-found state immediately. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/client/hooks/useItems.ts | 11 ++++++++++- src/client/hooks/useSetups.ts | 11 ++++++++++- src/client/hooks/useThreads.ts | 4 +++- src/client/lib/api.ts | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/client/hooks/useItems.ts b/src/client/hooks/useItems.ts index 30eccd2..51c5bf4 100644 --- a/src/client/hooks/useItems.ts +++ b/src/client/hooks/useItems.ts @@ -1,6 +1,13 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import type { CreateItem } from "../../shared/types"; -import { apiDelete, apiGet, apiPost, apiPut, apiUpload } from "../lib/api"; +import { + ApiError, + apiDelete, + apiGet, + apiPost, + apiPut, + apiUpload, +} from "../lib/api"; interface Item { id: number; @@ -45,6 +52,8 @@ export function useItem(id: number | null) { queryKey: ["items", id], queryFn: () => apiGet(`/api/items/${id}`), enabled: id != null, + retry: (count, error) => + error instanceof ApiError && error.status === 404 ? false : count < 3, }); } diff --git a/src/client/hooks/useSetups.ts b/src/client/hooks/useSetups.ts index 4149bc4..b0f6385 100644 --- a/src/client/hooks/useSetups.ts +++ b/src/client/hooks/useSetups.ts @@ -1,5 +1,12 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; -import { apiDelete, apiGet, apiPatch, apiPost, apiPut } from "../lib/api"; +import { + ApiError, + apiDelete, + apiGet, + apiPatch, + apiPost, + apiPut, +} from "../lib/api"; interface SetupListItem { id: number; @@ -50,6 +57,8 @@ export function useSetup(setupId: number | null) { queryKey: ["setups", setupId], queryFn: () => apiGet(`/api/setups/${setupId}`), enabled: setupId != null, + retry: (count, error) => + error instanceof ApiError && error.status === 404 ? false : count < 3, }); } diff --git a/src/client/hooks/useThreads.ts b/src/client/hooks/useThreads.ts index 9cf57c3..4f22c7c 100644 --- a/src/client/hooks/useThreads.ts +++ b/src/client/hooks/useThreads.ts @@ -1,5 +1,5 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; -import { apiDelete, apiGet, apiPost, apiPut } from "../lib/api"; +import { ApiError, apiDelete, apiGet, apiPost, apiPut } from "../lib/api"; interface ThreadListItem { id: number; @@ -61,6 +61,8 @@ export function useThread(threadId: number | null) { queryKey: ["threads", threadId], queryFn: () => apiGet(`/api/threads/${threadId}`), enabled: threadId != null, + retry: (count, error) => + error instanceof ApiError && error.status === 404 ? false : count < 3, }); } diff --git a/src/client/lib/api.ts b/src/client/lib/api.ts index 71dbea2..c7fdc0d 100644 --- a/src/client/lib/api.ts +++ b/src/client/lib/api.ts @@ -1,4 +1,4 @@ -class ApiError extends Error { +export class ApiError extends Error { constructor( message: string, public status: number,