[Performance] QueryClient initialized with default config — no retry logic, aggressive cache invalidation, poor offline UX
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- react, tauri, typescript
- 领域
- desktop, frontend, performance
调研方向
Start by reading src/main.tsx to understand the existing QueryClient setup, then inspect App.tsx and current TanStack Query usage before choosing centralized error handling. Reproduce a failed request with network throttling, configure the requested retry and cache behavior, add the described boundary if appropriate, and verify that transient failures retry and recovered data is refreshed.
由索引模型根据 Issue 内容生成。
描述
Description
The React application in src/main.tsx is wrapped with QueryClientProvider from TanStack Query, but the QueryClient is initialized with default configuration and no error handlers, retry logic, or cache strategies:
const queryClient = new QueryClient();
const container = document.getElementById("root");
const root = createRoot(container!);
root.render(
<QueryClientProvider client={queryClient}>
<ThemeProvider>
<App />
</ThemeProvider>
</QueryClientProvider>,
);
This means:
-
No retry logic on network failures: If an API request fails, TanStack Query will not retry automatically. A transient network error (timeout, temporary unavailability) will immediately show an error to the user instead of retrying.
-
No error boundary: Failed API requests have no centralized error handler. Each component must manually handle errors, leading to inconsistent error UI and potential crashes.
-
Aggressive cache invalidation: With default settings, cached data is discarded immediately, causing excessive API calls when navigating between views.
-
No stale-while-revalidate pattern: The app doesn't leverage TanStack Query's ability to show stale data while fetching fresh data in the background.
-
Missing mutation defaults: Form submissions and other mutations have no centralized error or success handling.
Users will experience:
- Frequent errors on weak network connections
- Slow performance due to redundant API calls
- Inconsistent error handling across screens
- Poor offline UX
Steps to Reproduce
- Open CommDesk on a slow or unstable network (simulate with browser DevTools throttling)
- Perform an API call (login, load community data, etc.)
- While the request is in flight, introduce a network error (disable network)
- Observe that the request fails immediately and shows an error to the user
- Re-enable network; the app does NOT retry automatically
Expected result: TanStack Query automatically retries failed requests with exponential backoff.
Actual result: Failed request shows error immediately with no retry.
Expected Behavior
QueryClient should be configured with:
- Default retry strategy (3 retries with exponential backoff for 5xx errors)
- Cache stale time (5 minutes before data is considered stale)
- Garbage collection time (10 minutes before unused cache is deleted)
- Default error handler for all queries and mutations
- Stale-while-revalidate behavior
Root Cause
QueryClient was initialized with defaults without considering the Tauri desktop environment, which has network instability concerns and limited bandwidth.
Proposed Fix
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { createRoot } from "react-dom/client";
import { ThemeProvider } from "./theme/provider";
import App from "./App";
const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 5 * 60 * 1000, // 5 minutes
gcTime: 10 * 60 * 1000, // 10 minutes (cache time)
retry: (failureCount, error) => {
// Retry on network errors and 5xx, but not on 4xx client errors
if (failureCount > 3) return false;
if (error instanceof Error && error.message.includes("401")) return false;
if (error instanceof Error && error.message.includes("403")) return false;
return true;
},
retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000),
},
mutations: {
retry: 1,
retryDelay: 1000,
},
},
});
const container = document.getElementById("root");
const root = createRoot(container!);
root.render(
<QueryClientProvider client={queryClient}>
<ThemeProvider>
<App />
</ThemeProvider>
</QueryClientProvider>,
);
Additionally, implement a global query error boundary in App.tsx:
import { useQueryErrorResetBoundary } from "@tanstack/react-query";
import { ErrorBoundary } from "react-error-boundary";
function App() {
const { reset } = useQueryErrorResetBoundary();
return (
<ErrorBoundary onReset={reset} fallback={<ErrorFallback />}>
{/* App content */}
</ErrorBoundary>
);
}
Environment
- File:
src/main.tsx - Severity: Medium (poor UX on network instability, excessive API calls)
Checklist
- I have searched existing issues and confirmed this is not a duplicate
- I have read the Contributing.md guidelines
- I have provided clear steps to reproduce the issue
- I have described expected vs. actual behavior clearly
- This issue title is clear and specific
- This repository has been verified as NSOC on https://www.nsoc.in/projects
@NexGenStudioDev Could you please /assign this issue to me? I would like to configure TanStack Query with proper defaults and error handling under NSOC '26.
/assign
- 主要语言
- TypeScript
- 星标
- 7
- 派生
- 17
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
NexGenStudioDev/CommDesk 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
NexGenStudioDev/CommDesk#140 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
NexGenStudioDev/CommDesk#138 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
NexGenStudioDev/CommDesk#130 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
NexGenStudioDev/CommDesk#123 · 2 条评论 ·
-
[UX] Hardcoded window dimensions not DPI-aware — UI broken on high-DPI displays可能重新可做 @anshul23102 于 83 天前认领,目前没有进行中的 PR。 未关闭
NexGenStudioDev/CommDesk#141 · 已指派 1 人 ·
查看 NexGenStudioDev/CommDesk 的全部 Issue
相似的 Issue
-
priority: P2
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 65/100
prime-radiant-inc/evener#3291 ·
维护者通常 1 天内回复
-
accessibility bug revealjs
难度 2/5 1-3 小时 新手友好度 84/100
quarto-dev/quarto-cli#14961 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 90/100
supabase/agent-skills#614 ·
-
Content
难度 2/5 1-3 小时 新手友好度 68/100
RunestoneInteractive/rs#1559 · 1 条评论 ·
维护者通常 2 天内回复