diff --git a/src/use-swr.ts b/src/use-swr.ts index e885ed4b80..6da64b0f36 100644 --- a/src/use-swr.ts +++ b/src/use-swr.ts @@ -167,7 +167,11 @@ function useSWR( fn = config.fetcher } - const initialData = cache.get(key) || config.initialData + if (config.initialData && !cache.has(key)) { + cache.set(key, config.initialData, false) + } + + const initialData = cache.get(key) const initialError = cache.get(keyErr) // if a state is accessed (data, error or isValidating), @@ -366,7 +370,7 @@ function useSWR( // and trigger a revalidation const currentHookData = stateRef.current.data - const latestKeyedData = cache.get(key) || config.initialData + const latestKeyedData = cache.get(key) // update the state if the key changed (not the inital render) or cache updated if (