Skip to content

Commit 8f5a389

Browse files
committed
fix: freeze inFlightResponse object and conditionally register revalidator
1 parent 1689727 commit 8f5a389

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/request-handler.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import { enhanceError, withErrorHandling } from './error-handler';
2626
import { FUNCTION } from './constants';
2727
import { buildConfig } from './config-handler';
2828

29-
const inFlightResponse = {
29+
const inFlightResponse = Object.freeze({
3030
isFetching: true,
31-
};
31+
});
3232

3333
/**
3434
* Sends an HTTP request to the specified URL using the provided configuration and returns a typed response.
@@ -331,15 +331,18 @@ export async function fetchf<
331331
setInFlightPromise(_cacheKey, doRequestPromise);
332332
}
333333

334-
addRevalidator(
335-
_cacheKey,
336-
requestWithErrorHandling,
337-
undefined,
338-
staleTime,
339-
requestWithErrorHandling,
340-
!!refetchOnFocus,
341-
!!refetchOnReconnect,
342-
);
334+
// Only register revalidator when revalidation features are actually requested
335+
if (staleTime || refetchOnFocus || refetchOnReconnect) {
336+
addRevalidator(
337+
_cacheKey,
338+
requestWithErrorHandling,
339+
undefined,
340+
staleTime,
341+
requestWithErrorHandling,
342+
!!refetchOnFocus,
343+
!!refetchOnReconnect,
344+
);
345+
}
343346
}
344347

345348
return doRequestPromise;

0 commit comments

Comments
 (0)