Skip to content

Commit 9f36b40

Browse files
author
Simen Owesen-Lein
committed
bugfix: make suspense and revalidateIfStale work together
1 parent ef400ea commit 9f36b40

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/use-swr.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,14 @@ export const useSWRHandler = <Data = any, Error = any>(
9797
// If it's paused, we skip revalidation.
9898
if (getConfig().isPaused()) return false
9999

100-
return suspense
101-
? // Under suspense mode, it will always fetch on render if there is no
102-
// stale data so no need to revalidate immediately on mount again.
103-
!isUndefined(data)
104-
: // If there is no stale data, we need to revalidate on mount;
105-
// If `revalidateIfStale` is set to true, we will always revalidate.
106-
isUndefined(data) || config.revalidateIfStale
100+
// Under suspense mode, it will always fetch on render if there is no
101+
// stale data so no need to revalidate immediately on mount again.
102+
// If data exists, only revalidate if `revalidateIfStale` is true.
103+
if (suspense) return isUndefined(data) ? false : config.revalidateIfStale
104+
105+
// If there is no stale data, we need to revalidate on mount;
106+
// If `revalidateIfStale` is set to true, we will always revalidate.
107+
return isUndefined(data) || config.revalidateIfStale
107108
}
108109

109110
// Resolve the current validating state.

0 commit comments

Comments
 (0)