|
1 | 1 | 'use client' |
2 | | -import { |
3 | | - useState, |
4 | | - useEffect, |
5 | | - useMemo, |
6 | | - useRef, |
7 | | - useCallback, |
8 | | - startTransition |
9 | | -} from 'react' |
| 2 | +import { useState, useEffect, useMemo, useRef, useCallback } from 'react' |
10 | 3 |
|
11 | 4 | import { |
12 | 5 | abortControllers, |
@@ -55,7 +48,6 @@ import { |
55 | 48 | createImperativeFetch, |
56 | 49 | getMiliseconds, |
57 | 50 | getTimePassed, |
58 | | - mutateData, |
59 | 51 | revalidate, |
60 | 52 | useIsomorphicLayoutEffect |
61 | 53 | } from '../utils' |
@@ -433,6 +425,10 @@ export function useFetch<FetchDataType = any, TransformData = any>( |
433 | 425 |
|
434 | 426 | const { data, loading, online, error, completedAttempts } = fetchState |
435 | 427 |
|
| 428 | + const thisCache = paginationCache ?? normalCache ?? data ?? def ?? null |
| 429 | + |
| 430 | + const rawJSON = serialize(data) |
| 431 | + |
436 | 432 | const isLoading = isExpired ? isPending(resolvedKey) || loading : false |
437 | 433 |
|
438 | 434 | const loadingFirst = |
@@ -1451,7 +1447,13 @@ export function useFetch<FetchDataType = any, TransformData = any>( |
1451 | 1447 | return () => clearTimeout(handler) |
1452 | 1448 | } |
1453 | 1449 |
|
1454 | | - revalidationLogic() |
| 1450 | + const startRevalidate = setTimeout(() => { |
| 1451 | + revalidationLogic() |
| 1452 | + }, 0) |
| 1453 | + |
| 1454 | + return () => { |
| 1455 | + clearTimeout(startRevalidate) |
| 1456 | + } |
1455 | 1457 | }, [ |
1456 | 1458 | resolvedKey, |
1457 | 1459 | serialize(optionsConfig), |
@@ -1561,7 +1563,7 @@ Learn more: https://httpr.vercel.app/docs/api#suspense |
1561 | 1563 | hasErrors.get(resolvedDataKey) || hasErrors.get(resolvedKey) || error |
1562 | 1564 |
|
1563 | 1565 | const dataCandidate = |
1564 | | - (error && isFailed ? (cacheIfError ? data : null) : data) ?? def |
| 1566 | + (error && isFailed ? (cacheIfError ? thisCache : null) : thisCache) ?? def |
1565 | 1567 |
|
1566 | 1568 | const responseData = isDefined(dataCandidate) |
1567 | 1569 | ? transform!(dataCandidate) |
|
0 commit comments