Skip to content

Commit 63fb09b

Browse files
authored
fix: isValidating should be false when no fetcher is provided (#1352)
1 parent 381865a commit 63fb09b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/use-swr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export const useSWRHandler = <Data = any, Error = any>(
214214

215215
// Resolve the current validating state.
216216
const resolveValidating = () => {
217-
if (!key) return false
217+
if (!key || !fn) return false
218218
if (cache.get(keyValidating)) return true
219219

220220
// If it's not mounted yet and it should revalidate on mount, revalidate.

test/use-swr-local-mutation.test.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { act, render, screen, fireEvent } from '@testing-library/react'
22
import React, { useEffect, useState } from 'react'
33
import useSWR, { mutate, createCache, SWRConfig } from 'swr'
44
import { serialize } from '../src/utils/serialize'
5-
import { createResponse, sleep, nextTick } from './utils'
5+
import { createResponse, sleep, nextTick, createKey } from './utils'
66

77
describe('useSWR - local mutation', () => {
88
it('should trigger revalidation programmatically', async () => {
@@ -699,4 +699,14 @@ describe('useSWR - local mutation', () => {
699699
await act(() => sleep(100))
700700
await screen.findByText('data: 1')
701701
})
702+
703+
it('isValidating should be false when no fetcher is provided', async () => {
704+
const key = createKey()
705+
function Page() {
706+
const { isValidating } = useSWR(key)
707+
return <p>{isValidating.toString()}</p>
708+
}
709+
render(<Page />)
710+
screen.getByText('false')
711+
})
702712
})

0 commit comments

Comments
 (0)