From 92a5cfc0e6960913ae892a1b7518e43b361d682f Mon Sep 17 00:00:00 2001 From: Wali Mohammad Kadri Date: Sun, 29 Jun 2025 04:33:36 +0530 Subject: [PATCH 1/4] fix(types): export FetcherResponse type Fixes #3038 --- src/index/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index/index.ts b/src/index/index.ts index 2ae26b143..559a5e418 100644 --- a/src/index/index.ts +++ b/src/index/index.ts @@ -32,5 +32,6 @@ export type { Middleware, Arguments, State, - ScopedMutator + ScopedMutator, + FetcherResponse } from '../_internal' From 2bc18a217561ccd9720c001862e630d406789fe0 Mon Sep 17 00:00:00 2001 From: Wali Mohammad Kadri Date: Sun, 29 Jun 2025 04:47:27 +0530 Subject: [PATCH 2/4] fix(loading): Prevent isLoading from being true with fallbackData When `fallbackData` is provided, `isLoading` should not be true initially. Instead, `isValidating` should be true to indicate background revalidation. This prevents a "flash of skeleton" UI when initial data is available. Fixes #3046 --- src/index/use-swr.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index/use-swr.ts b/src/index/use-swr.ts index 21c42a9c2..291f43ee2 100644 --- a/src/index/use-swr.ts +++ b/src/index/use-swr.ts @@ -195,7 +195,7 @@ export const useSWRHandler = ( return { isValidating: true, - isLoading: true, + isLoading: isUndefined(fallback), ...snapshot } } @@ -278,8 +278,8 @@ export const useSWRHandler = ( const returnedData = keepPreviousData ? isUndefined(cachedData) - // checking undefined to avoid null being fallback as well - ? isUndefined(laggyDataRef.current) + ? // checking undefined to avoid null being fallback as well + isUndefined(laggyDataRef.current) ? data : laggyDataRef.current : cachedData @@ -390,7 +390,7 @@ export const useSWRHandler = ( const initialState: State = { isValidating: true } // It is in the `isLoading` state, if and only if there is no cached data. // This bypasses fallback data and laggy data. - if (isUndefined(getCache().data)) { + if (isUndefined(getCache().data) && isUndefined(fallback)) { initialState.isLoading = true } try { From 03d953a702e475711664aa39f823aa358013aea4 Mon Sep 17 00:00:00 2001 From: Wali Mohammad Kadri Date: Sun, 29 Jun 2025 04:49:03 +0530 Subject: [PATCH 3/4] Revert "fix(loading): Prevent isLoading from being true with fallbackData" This reverts commit 2bc18a217561ccd9720c001862e630d406789fe0. --- src/index/use-swr.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index/use-swr.ts b/src/index/use-swr.ts index 291f43ee2..21c42a9c2 100644 --- a/src/index/use-swr.ts +++ b/src/index/use-swr.ts @@ -195,7 +195,7 @@ export const useSWRHandler = ( return { isValidating: true, - isLoading: isUndefined(fallback), + isLoading: true, ...snapshot } } @@ -278,8 +278,8 @@ export const useSWRHandler = ( const returnedData = keepPreviousData ? isUndefined(cachedData) - ? // checking undefined to avoid null being fallback as well - isUndefined(laggyDataRef.current) + // checking undefined to avoid null being fallback as well + ? isUndefined(laggyDataRef.current) ? data : laggyDataRef.current : cachedData @@ -390,7 +390,7 @@ export const useSWRHandler = ( const initialState: State = { isValidating: true } // It is in the `isLoading` state, if and only if there is no cached data. // This bypasses fallback data and laggy data. - if (isUndefined(getCache().data) && isUndefined(fallback)) { + if (isUndefined(getCache().data)) { initialState.isLoading = true } try { From e2f11af62f712063022e8331e8931d6de24c9320 Mon Sep 17 00:00:00 2001 From: Wali Mohammad Kadri Date: Sun, 29 Jun 2025 04:49:47 +0530 Subject: [PATCH 4/4] fix(loading): Prevent isLoading from being true with fallbackData When `fallbackData` is provided, `isLoading` should not be true initially. Instead, `isValidating` should be true to indicate background revalidation. This prevents a "flash of skeleton" UI when initial data is available. Fixes #3046 --- src/index/use-swr.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index/use-swr.ts b/src/index/use-swr.ts index 21c42a9c2..b660a054f 100644 --- a/src/index/use-swr.ts +++ b/src/index/use-swr.ts @@ -195,7 +195,7 @@ export const useSWRHandler = ( return { isValidating: true, - isLoading: true, + isLoading: isUndefined(fallback), ...snapshot } } @@ -278,8 +278,8 @@ export const useSWRHandler = ( const returnedData = keepPreviousData ? isUndefined(cachedData) - // checking undefined to avoid null being fallback as well - ? isUndefined(laggyDataRef.current) + ? // checking undefined to avoid null being fallback as well + isUndefined(laggyDataRef.current) ? data : laggyDataRef.current : cachedData