Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

refactor(react-query): replace magic number with named constant in suspense timers #9607

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

Open
m2na7 wants to merge 1 commit into TanStack:main
base: main
Choose a base branch
Loading
from m2na7:refactor/replace-magic-number-with-constant
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/react-query/src/suspense.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ export const ensureSuspenseTimers = (
if (defaultedOptions.suspense) {
// Handle staleTime to ensure minimum 1000ms in Suspense mode
// This prevents unnecessary refetching when components remount after suspending
const MIN_SUSPENSE_TIME_MS = 1000

const clamp = (value: number | 'static' | undefined) =>
value === 'static' ? value : Math.max(value ?? 1000, 1000)
value === 'static' ? value : Math.max(value ?? MIN_SUSPENSE_TIME_MS, MIN_SUSPENSE_TIME_MS)

const originalStaleTime = defaultedOptions.staleTime
defaultedOptions.staleTime =
Expand All @@ -35,7 +36,7 @@ export const ensureSuspenseTimers = (
: clamp(originalStaleTime)

if (typeof defaultedOptions.gcTime === 'number') {
defaultedOptions.gcTime = Math.max(defaultedOptions.gcTime, 1000)
defaultedOptions.gcTime = Math.max(defaultedOptions.gcTime, MIN_SUSPENSE_TIME_MS)
}
}
}
Expand Down

AltStyle によって変換されたページ (->オリジナル) /