From 17891a08392fea21a44d95d2697f798ecef65da9 Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Wed, 10 Jul 2024 15:19:42 -0400 Subject: [PATCH 1/2] Single Fetch: proxy request signal through on interrupted loader calls --- .changeset/fluffy-ways-bathe.md | 5 +++++ packages/remix-react/single-fetch.tsx | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 .changeset/fluffy-ways-bathe.md diff --git a/.changeset/fluffy-ways-bathe.md b/.changeset/fluffy-ways-bathe.md new file mode 100644 index 00000000000..c597ae8b2a2 --- /dev/null +++ b/.changeset/fluffy-ways-bathe.md @@ -0,0 +1,5 @@ +--- +"@remix-run/react": patch +--- + +Singl Fetch: proxy abort signal through dataStrategy for loaders for request cancellation diff --git a/packages/remix-react/single-fetch.tsx b/packages/remix-react/single-fetch.tsx index 880ce796b87..1543dab05cf 100644 --- a/packages/remix-react/single-fetch.tsx +++ b/packages/remix-react/single-fetch.tsx @@ -192,12 +192,13 @@ function singleFetchLoaderStrategy( m.resolve(async (handler): Promise => { let result: unknown; let url = stripIndexParam(singleFetchUrl(request.url)); + let init = await createRequestInit(request); // When a route has a client loader, it calls it's singular server loader if (manifest.routes[m.route.id].hasClientLoader) { result = await handler(async () => { url.searchParams.set("_routes", m.route.id); - let { data } = await fetchAndDecode(url); + let { data } = await fetchAndDecode(url, init); return unwrapSingleFetchResults( data as SingleFetchResults, m.route.id @@ -214,7 +215,7 @@ function singleFetchLoaderStrategy( matches.filter((m) => m.shouldLoad).map((m) => m.route), url ); - singleFetchPromise = fetchAndDecode(url).then( + singleFetchPromise = fetchAndDecode(url, init).then( ({ data }) => data as SingleFetchResults ); } @@ -307,7 +308,7 @@ export function singleFetchUrl(reqUrl: URL | string) { return url; } -async function fetchAndDecode(url: URL, init?: RequestInit) { +async function fetchAndDecode(url: URL, init: RequestInit) { let res = await fetch(url, init); // Don't do a hard check against the header here. We'll get `text/x-turbo` // when we have a running server, but if folks want to prerender `.data` files From b51a8e3b06066b55e6a921198b67b9b443b93a84 Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Wed, 10 Jul 2024 16:38:04 -0400 Subject: [PATCH 2/2] Update .changeset/fluffy-ways-bathe.md --- .changeset/fluffy-ways-bathe.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/fluffy-ways-bathe.md b/.changeset/fluffy-ways-bathe.md index c597ae8b2a2..16cbe962953 100644 --- a/.changeset/fluffy-ways-bathe.md +++ b/.changeset/fluffy-ways-bathe.md @@ -2,4 +2,4 @@ "@remix-run/react": patch --- -Singl Fetch: proxy abort signal through dataStrategy for loaders for request cancellation +Single Fetch: Proxy `request.signal` through `dataStrategy` for `loader` calls to fix cancellation