Skip to content

Commit

Permalink
Fix initial isValidating when isPaused() returns true (#1440)
Browse files Browse the repository at this point in the history
* Fix initial isValidating when isPaused returns true

* Update unit test description
  • Loading branch information
anothertempore committed Sep 10, 2021
1 parent e789a4d commit c00f0b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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')
})
})

0 comments on commit c00f0b4

Please sign in to comment.