Skip to content
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

fix(react-query): ensureSuspenseTimers should ALWAYS set staleTime to 1000 when it is below 1000. #8398

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
13 changes: 8 additions & 5 deletions packages/react-query/src/suspense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ export const ensureSuspenseTimers = (
defaultedOptions: DefaultedQueryObserverOptions<any, any, any, any, any>,
) => {
if (defaultedOptions.suspense) {
// Always set stale time when using suspense to prevent
// fetching again when directly mounting after suspending
if (defaultedOptions.staleTime === undefined) {
defaultedOptions.staleTime = 1000
}
// Handle staleTime to ensure minimum 1000ms in Suspense mode
// This prevents unnecessary refetching when components remount after suspending
defaultedOptions.staleTime =
typeof defaultedOptions.staleTime === 'function'
? (...args: Parameters<typeof defaultedOptions.staleTime>) =>
Math.max(defaultedOptions.staleTime(...args) ?? 1000, 1000)
: Math.max(defaultedOptions.staleTime ?? 1000, 1000)

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