Skip to content

Commit

Permalink
bugfix: make suspense and revalidateIfStale work together
Browse files Browse the repository at this point in the history
  • Loading branch information
simowe committed Feb 10, 2022
1 parent ef400ea commit 9f36b40
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/use-swr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ export const useSWRHandler = <Data = any, Error = any>(
// If it's paused, we skip revalidation.
if (getConfig().isPaused()) return false

return suspense
? // Under suspense mode, it will always fetch on render if there is no
// stale data so no need to revalidate immediately on mount again.
!isUndefined(data)
: // If there is no stale data, we need to revalidate on mount;
// If `revalidateIfStale` is set to true, we will always revalidate.
isUndefined(data) || config.revalidateIfStale
// Under suspense mode, it will always fetch on render if there is no
// stale data so no need to revalidate immediately on mount again.
// If data exists, only revalidate if `revalidateIfStale` is true.
if (suspense) return isUndefined(data) ? false : config.revalidateIfStale

// If there is no stale data, we need to revalidate on mount;
// If `revalidateIfStale` is set to true, we will always revalidate.
return isUndefined(data) || config.revalidateIfStale
}

// Resolve the current validating state.
Expand Down

0 comments on commit 9f36b40

Please sign in to comment.