Skip to content
Open
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
7 changes: 6 additions & 1 deletion src/_internal/utils/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ const revalidateAllKeys = (
type: RevalidateEvent
) => {
for (const key in revalidators) {
if (revalidators[key][0]) revalidators[key][0](type)
const callbacks = revalidators[key]
if (callbacks) {
for (const callback of [...callbacks]) {
callback(type)
}
}
}
}

Expand Down
40 changes: 40 additions & 0 deletions test/use-swr-focus.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,46 @@ describe('useSWR - focus', () => {
await screen.findByText('data: 1')
})

it('should revalidate active hooks when another hook with the same key is paused', async () => {
let value = 0
const key = createKey()
const fetcher = () => value++

function PausedConsumer() {
useSWR(key, fetcher, {
dedupingInterval: 0,
focusThrottleInterval: 0,
isPaused: () => true
})
return null
}

function ActiveConsumer() {
const { data } = useSWR(key, fetcher, {
dedupingInterval: 0,
focusThrottleInterval: 0
})
return <div>data: {data}</div>
}

function Page() {
return (
<>
<PausedConsumer />
<ActiveConsumer />
</>
)
}

renderWithConfig(<Page />)
await screen.findByText('data: 0')

await waitForNextTick()
await focusWindow()

await screen.findByText('data: 1')
})

it('should not revalidate on focus when key changes in the same tick', async () => {
const fetchLogs = []

Expand Down