diff --git a/_internal/types.ts b/_internal/types.ts index 95b3cdac0..f2a8b750a 100644 --- a/_internal/types.ts +++ b/_internal/types.ts @@ -429,9 +429,9 @@ export type RevalidateCallback = ( export interface Cache { keys(): IterableIterator - get(key: Key): State | undefined - set(key: Key, value: State): void - delete(key: Key): void + get(key: string): State | undefined + set(key: string, value: State): void + delete(key: string): void } export interface StateDependencies { diff --git a/_internal/utils/helper.ts b/_internal/utils/helper.ts index 8d9b8401c..7356b9426 100644 --- a/_internal/utils/helper.ts +++ b/_internal/utils/helper.ts @@ -36,7 +36,7 @@ export const createCacheHelper = >( const state = SWRGlobalState.get(cache) as GlobalState return [ // Getter - () => (cache.get(key) || EMPTY_CACHE) as T, + () => ((!isUndefined(key) && cache.get(key)) || EMPTY_CACHE) as T, // Setter (info: T) => { if (!isUndefined(key)) { @@ -61,7 +61,7 @@ export const createCacheHelper = >( } // If we haven't done any client-side updates, we return the current value. - return (cache.get(key) || EMPTY_CACHE) as T + return ((!isUndefined(key) && cache.get(key)) || EMPTY_CACHE) as T } ] as const }