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 initial isValidating when isPaused() returns true #1440

Merged
merged 3 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/use-swr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ export const useSWRHandler = <Data = any, Error = any>(

// A revalidation must be triggered when mounted if:
// - `revalidateOnMount` is explicitly set to `true`.
// - `isPaused()` returns to `true`.
// - Suspense mode and there's stale data for the initial render.
// - Not suspense mode and there is no fallback data and `revalidateIfStale` is enabled.
// - `revalidateIfStale` is enabled but `data` is not defined.
const shouldRevalidateOnMount = () => {
if (!isUndefined(revalidateOnMount)) return revalidateOnMount
if (configRef.current.isPaused()) return false

return suspense
? !initialMountedRef.current && !isUndefined(data)
Expand Down
15 changes: 15 additions & 0 deletions test/use-swr-revalidate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,19 @@ describe('useSWR - revalidate', () => {
await act(() => sleep(70))
screen.getByText('count: 2')
})

it('should set initial isValidating be false when config.isPaused returns true', async () => {
function Page() {
const { isValidating } = useSWR(
'set isValidating for config.isPaused',
() => '123',
{ isPaused: () => true }
)

return <div>{isValidating ? 'true' : 'false'}</div>
}

render(<Page />)
screen.getByText('false')
})
})