-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
feat: add default web-streams based server entry #14759
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
base: dev
Are you sure you want to change the base?
Conversation
|
|
Hi @edmundhung, Welcome, and thank you for contributing to React Router! Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once. You may review the CLA and sign it by adding your name to contributors.yml. Once the CLA is signed, the If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at [email protected]. Thanks! - The Remix team |
|
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
dd552d8 to
188d4a3
Compare
| // ReactDOMServer.renderToReadableStream is not available in Node.js until React 19.2.0+ | ||
| if (typeof ReactDOMServer.renderToReadableStream !== "function") { | ||
| throw new Error( | ||
| `ReactDOMServer.renderToReadableStream() is not available. ` + | ||
| `React Router uses this API when @react-router/node is not installed. ` + | ||
| `Please install @react-router/node, or provide a custom entry.server.tsx/jsx file in your app directory.`, | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check is still needed because renderToReadableStream is only available in Node.js from React 19.2.0+.
Without this check, users on React 18.x or React 19.0.0-19.1.x running on Node.js would get a cryptic error because renderToReadableStream is undefined.
| // ReactDOMServer.renderToPipeableStream is only available in Node.js | ||
| if (typeof ReactDOMServer.renderToPipeableStream !== "function") { | ||
| throw new Error( | ||
| `Running the Node.js server entry on a non-Node runtime. ` + | ||
| `React Router uses this when @react-router/node is listed in your dependencies. ` + | ||
| `Remove it, or provide a custom entry.server.tsx/jsx file in your app directory.`, | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helps users migrating from Node.js to non-Node runtimes. If they forget to remove @react-router/node, React Router selects this entry but renderToPipeableStream won't be available.
The check provides a clear error message instead of a cryptic failure.
|
We moved away from this "dependency detection" approach in v7 but I don't recall the specific underlying reason. I'm hesitant to add it back without tracking that down and seeing if it still applies and/or should be reconsidered. |
Good to know that. I'm curious what the dependency detection was being used for? Was it for something beyond server entry files? I can understand why it might not be preferred. Happy to explore alternatives. |
This PR adds a default
entry.server.tsxusingrenderToReadableStream.Previously, users without
@react-router/nodehad to provide a custom server entry. Now React Router uses a web-streams based entry when@react-router/nodeisn't listed independencies, which supports both non-Node runtimes and modern Node versions with React 19.2.0+.revealcommand returns the corresponding entry based on whether@react-router/nodeis listed.