fix: preserve fetch preconnect in abort wrapper

This commit is contained in:
Peter Steinberger
2026-01-21 17:45:18 +00:00
parent c129f0bbaa
commit 9605ad76c5

View File

@@ -1,3 +1,7 @@
type FetchWithPreconnect = typeof fetch & {
preconnect: (url: string, init?: { credentials?: RequestCredentials }) => void;
};
export function wrapFetchWithAbortSignal(fetchImpl: typeof fetch): typeof fetch {
const wrapped = ((input: RequestInfo | URL, init?: RequestInit) => {
const signal = init?.signal;
@@ -25,7 +29,11 @@ export function wrapFetchWithAbortSignal(fetchImpl: typeof fetch): typeof fetch
});
}
return response;
}) as typeof fetch;
}) as FetchWithPreconnect;
wrapped.preconnect =
typeof fetchImpl.preconnect === "function" ? fetchImpl.preconnect.bind(fetchImpl) : () => {};
return Object.assign(wrapped, fetchImpl);
}