From 613742897707a108cffdfc918a0527cf798ded10 Mon Sep 17 00:00:00 2001 From: danybeltran Date: Sun, 9 Nov 2025 05:16:41 -0600 Subject: [PATCH] fix(cache): Fixes stale data value --- package.json | 2 +- src/hooks/use-fetch.ts | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 2501435..bc5bded 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "http-react", - "version": "3.8.6", + "version": "3.8.7", "description": "React hooks for data fetching", "main": "dist/index.js", "scripts": { diff --git a/src/hooks/use-fetch.ts b/src/hooks/use-fetch.ts index 3a38d03..7199d4f 100644 --- a/src/hooks/use-fetch.ts +++ b/src/hooks/use-fetch.ts @@ -244,10 +244,6 @@ export function useFetch( const ageKey = ['max-age', resolvedDataKey].join('-') - const paginationCache = cacheProvider.get(resolvedDataKey) - - const normalCache = cacheProvider.get(resolvedKey) - const maxAge = getMiliseconds(maxCacheAge || '0 ms') // Revalidates if passed maxCacheAge has changed @@ -425,9 +421,12 @@ export function useFetch( const { data, loading, online, error, completedAttempts } = fetchState - const thisCache = paginationCache ?? normalCache ?? data ?? def ?? null - - const rawJSON = serialize(data) + const thisCache = + cacheProvider.get(resolvedDataKey) ?? + cacheProvider.get(resolvedKey) ?? + data ?? + def ?? + null const isLoading = isExpired ? isPending(resolvedKey) || loading : false