Skip to content

Commit 386ab2b

Browse files
shudingnevilm-lt
authored andcommitted
Skip error retrying when document is not active and improve tests (vercel#1742)
* use the babel coverage reporter * improve coverage
1 parent d5c5e20 commit 386ab2b

File tree

2 files changed

+0
-58
lines changed

2 files changed

+0
-58
lines changed

src/use-swr.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ export const useSWRHandler = <Data = any, Error = any>(
7777
const configRef = useRef(config)
7878
const getConfig = () => configRef.current
7979
const isActive = () => getConfig().isVisible() && getConfig().isOnline()
80-
const patchFetchInfo = (info: { isValidating?: boolean; error?: any }) =>
81-
cache.set(keyInfo, mergeObjects(cache.get(keyInfo), info))
8280

8381
// Get the current state that SWR should return.
8482
const cached = cache.get(key)

test/use-swr-error.test.tsx

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -142,62 +142,6 @@ describe('useSWR - error', () => {
142142
screen.getByText('error: 0')
143143
})
144144

145-
it('should not retry when shouldRetryOnError function returns false', async () => {
146-
const key = createKey()
147-
let count = 0
148-
function Page() {
149-
const { data, error } = useSWR(
150-
key,
151-
() => createResponse(new Error('error: ' + count++), { delay: 100 }),
152-
{
153-
onErrorRetry: (_, __, ___, revalidate, revalidateOpts) => {
154-
revalidate(revalidateOpts)
155-
},
156-
dedupingInterval: 0,
157-
shouldRetryOnError: () => false
158-
}
159-
)
160-
if (error) return <div>{error.message}</div>
161-
return <div>hello, {data}</div>
162-
}
163-
renderWithConfig(<Page />)
164-
screen.getByText('hello,')
165-
166-
// mount
167-
await screen.findByText('error: 0')
168-
169-
await act(() => sleep(150))
170-
screen.getByText('error: 0')
171-
})
172-
173-
it('should retry when shouldRetryOnError function returns true', async () => {
174-
const key = createKey()
175-
let count = 0
176-
function Page() {
177-
const { data, error } = useSWR(
178-
key,
179-
() => createResponse(new Error('error: ' + count++), { delay: 100 }),
180-
{
181-
onErrorRetry: (_, __, ___, revalidate, revalidateOpts) => {
182-
revalidate(revalidateOpts)
183-
},
184-
dedupingInterval: 0,
185-
shouldRetryOnError: () => true
186-
}
187-
)
188-
if (error) return <div>{error.message}</div>
189-
return <div>hello, {data}</div>
190-
}
191-
renderWithConfig(<Page />)
192-
screen.getByText('hello,')
193-
194-
// mount
195-
await screen.findByText('error: 0')
196-
197-
await act(() => sleep(150))
198-
screen.getByText('error: 1')
199-
})
200-
201145
it('should trigger the onLoadingSlow and onSuccess event', async () => {
202146
const key = createKey()
203147
let loadingSlow = null,

0 commit comments

Comments
 (0)