From f1db96fdd4988a1384ddefa2b7d148b128ee8f97 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Fri, 9 Sep 2022 13:01:05 +0300 Subject: [PATCH] fix(fetchache): respect additional parameters passed to fetch --- .changeset/wicked-pumas-roll.md | 5 +++++ packages/fetchache/src/index.ts | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 .changeset/wicked-pumas-roll.md diff --git a/.changeset/wicked-pumas-roll.md b/.changeset/wicked-pumas-roll.md new file mode 100644 index 00000000000..31048d0015b --- /dev/null +++ b/.changeset/wicked-pumas-roll.md @@ -0,0 +1,5 @@ +--- +'fetchache': patch +--- + +Respect additional parameters to fetch diff --git a/packages/fetchache/src/index.ts b/packages/fetchache/src/index.ts index 07bcc412300..b017c77dbda 100644 --- a/packages/fetchache/src/index.ts +++ b/packages/fetchache/src/index.ts @@ -5,7 +5,7 @@ export interface FetchacheCacheEntry { body: string; } -type FetchFn = WindowOrWorkerGlobalScope['fetch']; +type FetchFn = (input: URL | RequestInfo, init: RequestInit, ...rest: any[]) => Promise; export interface FetchacheOptions { fetch: FetchFn; @@ -15,7 +15,7 @@ export interface FetchacheOptions { } export function fetchFactory({ fetch, Response, cache }: FetchacheOptions): FetchFn { - return async (input, init) => { + return async (input: URL | RequestInfo, init: RequestInit, ...rest: any[]) => { let url: string; let method = 'GET'; let headers: HeadersInit = {}; @@ -34,7 +34,7 @@ export function fetchFactory({ fetch, Response, cache }: FetchacheOptions): Fetc const entry = await cache.get(cacheKey); const policyRequest = policyRequestFrom(url, method, headers); if (!entry) { - const response = await fetch(input, init); + const response = await fetch(input, init, ...rest); const policy = new CachePolicy(policyRequest, policyResponseFrom(response)); @@ -65,7 +65,7 @@ export function fetchFactory({ fetch, Response, cache }: FetchacheOptions): Fetc ...headers, ...(revalidationHeaders as HeadersInit), }, - }); + }, ...rest); const revalidationPolicyRequest = policyRequestFrom(url, method, revalidationHeaders as HeadersInit);