Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single Fetch: proxy request signal through on interrupted loader calls #9738

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fluffy-ways-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/react": patch
---

Singl Fetch: proxy abort signal through dataStrategy for loaders for request cancellation
brophdawg11 marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 4 additions & 3 deletions packages/remix-react/single-fetch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,13 @@ function singleFetchLoaderStrategy(
m.resolve(async (handler): Promise<HandlerResult> => {
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
Expand All @@ -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
);
}
Expand Down Expand Up @@ -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
Expand Down