Skip to content

Commit 98b84dc

Browse files
committed
perf: improve request handling for retries with stale revalidation
1 parent 1ea9134 commit 98b84dc

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/request-handler.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,16 @@ export async function fetchf<
296296
};
297297

298298
// Inline and minimize function wrappers for performance
299+
// When retries are enabled, forward isStaleRevalidation so the first attempt
300+
// of a background SWR revalidation doesn't incorrectly mark the request as in-flight
299301
const baseRequest =
300-
retries > 0 ? () => withRetry(doRequestOnce, retryConfig) : doRequestOnce;
302+
retries > 0
303+
? (isStaleRevalidation = false) =>
304+
withRetry(
305+
(_, attempt) => doRequestOnce(isStaleRevalidation, attempt),
306+
retryConfig,
307+
)
308+
: doRequestOnce;
301309

302310
const requestWithErrorHandling = (isStaleRevalidation = false) =>
303311
withErrorHandling<ResponseData, RequestBody, QueryParams, PathParams>(

0 commit comments

Comments
 (0)