Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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/funny-suns-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-router/dev": patch
---

Cancel aborts timeouts created in the default entry.server.tsx file
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,4 @@
- yuleicul
- zeromask1337
- zheng-chuang
- remorses
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function handleRequest(
return new Promise((resolve, reject) => {
let shellRendered = false;
let userAgent = request.headers.get("user-agent");
let timeoutId: NodeJS.Timeout;

// Ensure requests from bots and SPA Mode renders wait for all content to load before responding
// https://react.dev/reference/react-dom/server/renderToPipeableStream#waiting-for-all-content-to-load-for-crawlers-and-static-generation
Expand All @@ -45,8 +46,10 @@ export default function handleRequest(
);

pipe(body);
clearTimeout(timeoutId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing here means abort will never be called in streaming scenarios that exceed the time limit since onShellReady fires when the shell is ready but there's still pending stuff to be streamed down, so this is basically clearing the time out at the start of the streamed content, regardless of how long it actually takes.

},
onShellError(error: unknown) {
clearTimeout(timeoutId);
reject(error);
},
onError(error: unknown) {
Expand All @@ -56,13 +59,14 @@ export default function handleRequest(
// reject and get logged in handleDocumentRequest.
if (shellRendered) {
console.error(error);
clearTimeout(timeoutId);
}
},
}
);

// Abort the rendering stream after the `streamTimeout` so it has time to
// flush down the rejected boundaries
setTimeout(abort, streamTimeout + 1000);
timeoutId = setTimeout(abort, streamTimeout + 1000);
});
}