-
Notifications
You must be signed in to change notification settings - Fork 3.1k
refactor: Phase 4 - Configure centralized request deduplication #700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6176492
refactor: Phase 4 - Configure centralized request deduplication
Wirasm f4e8828
added proper stale time for project task count
Wirasm 4054184
improve: Unified retry logic and task query enhancements
Wirasm 79a436c
fix: Correct useSmartPolling background interval logic
Wirasm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { QueryClient } from "@tanstack/react-query"; | ||
| import { createRetryLogic, STALE_TIMES } from "./queryPatterns"; | ||
|
|
||
| /** | ||
| * Centralized QueryClient configuration for the entire application | ||
| * | ||
| * Benefits: | ||
| * - Single source of truth for cache configuration | ||
| * - Automatic request deduplication for same query keys | ||
| * - Smart retry logic that avoids retrying on client errors | ||
| * - Optimized garbage collection and structural sharing | ||
| */ | ||
| export const queryClient = new QueryClient({ | ||
| defaultOptions: { | ||
| queries: { | ||
| // Default stale time - most data is considered fresh for 30 seconds | ||
| staleTime: STALE_TIMES.normal, | ||
|
|
||
| // Keep unused data in cache for 10 minutes (was 5 minutes) | ||
| gcTime: 10 * 60 * 1000, | ||
|
|
||
| // Smart retry logic - don't retry on 4xx errors or aborts | ||
| retry: createRetryLogic(2), | ||
|
|
||
| // Exponential backoff for retries | ||
| retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000), | ||
|
|
||
| // Disable aggressive refetching to reduce API calls | ||
| refetchOnWindowFocus: false, | ||
| refetchOnReconnect: false, | ||
| refetchOnMount: true, | ||
|
|
||
| // Network behavior | ||
| networkMode: "online", | ||
|
|
||
| // Enable structural sharing for efficient re-renders | ||
| structuralSharing: true, | ||
| }, | ||
|
|
||
| mutations: { | ||
| // No retries for mutations - let user explicitly retry | ||
| retry: false, | ||
|
|
||
| // Network behavior | ||
| networkMode: "online", | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| /** | ||
| * Create a test QueryClient with optimized settings for tests | ||
| * Used by test-utils.tsx for consistent test behavior | ||
| */ | ||
| export function createTestQueryClient(): QueryClient { | ||
| return new QueryClient({ | ||
| defaultOptions: { | ||
| queries: { | ||
| retry: false, | ||
| staleTime: 0, // Always fresh in tests | ||
| gcTime: 0, // No caching in tests | ||
| refetchOnWindowFocus: false, | ||
| }, | ||
| mutations: { | ||
| retry: false, | ||
| }, | ||
| }, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix polling inversion: background ends up polling faster than foreground.
useSmartPolling(10_000)returns 5s when not focused, which is faster than the 10s active interval and contradicts the polling guideline. Use visibility to pause when hidden and keep 10s while visible.📝 Committable suggestion
🤖 Prompt for AI Agents