From ed7a288946eda886b04ff6f20ed1193e17040b2a Mon Sep 17 00:00:00 2001 From: Naiyuan Qing <145280634+NevilleQingNY@users.noreply.github.com> Date: Tue, 7 Apr 2026 10:26:53 +0800 Subject: [PATCH] fix(web): prevent 404 on workspace switch and downgrade 404 log level - Skip issue refetch when store is cleared during workspace switch by tracking which issue was already loaded (loadedIdRef pattern) - Downgrade 404 responses from logger.error to logger.warn in ApiClient since resource-not-found is a normal business response, not a bug Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/web/features/issues/components/issue-detail.tsx | 12 +++++++++++- apps/web/shared/api/client.ts | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/web/features/issues/components/issue-detail.tsx b/apps/web/features/issues/components/issue-detail.tsx index 15b0f946..e3a5aaef 100644 --- a/apps/web/features/issues/components/issue-detail.tsx +++ b/apps/web/features/issues/components/issue-detail.tsx @@ -196,12 +196,22 @@ export function IssueDetail({ issueId, onDelete, defaultSidebarOpen = true, layo const issue = useIssueStore((s) => s.issues.find((i) => i.id === id)) ?? null; const [issueLoading, setIssueLoading] = useState(!issue); - // If issue isn't in the store yet, fetch and upsert it + // If issue isn't in the store yet, fetch and upsert it. + // loadedIdRef tracks which issue was already loaded — if it disappears + // from the store (workspace switch clears all issues), skip refetch. + const loadedIdRef = useRef(null); useEffect(() => { if (issue) { + loadedIdRef.current = id; setIssueLoading(false); return; } + // Issue was loaded for this id but vanished → store cleared (workspace switch) + if (loadedIdRef.current === id) { + loadedIdRef.current = null; + return; + } + // Issue not in store → fetch it setIssueLoading(true); api .getIssue(id) diff --git a/apps/web/shared/api/client.ts b/apps/web/shared/api/client.ts index 65004b34..fab5db81 100644 --- a/apps/web/shared/api/client.ts +++ b/apps/web/shared/api/client.ts @@ -113,7 +113,8 @@ export class ApiClient { if (!res.ok) { if (res.status === 401) this.handleUnauthorized(); const message = await this.parseErrorMessage(res, `API error: ${res.status} ${res.statusText}`); - this.logger.error(`← ${res.status} ${path}`, { rid, duration: `${Date.now() - start}ms`, error: message }); + const logLevel = res.status === 404 ? "warn" : "error"; + this.logger[logLevel](`← ${res.status} ${path}`, { rid, duration: `${Date.now() - start}ms`, error: message }); throw new Error(message); }