KEMBAR78
[Fizz] Add Node Web Streams bundle for SSR by sebmarkbage · Pull Request #33441 · facebook/react · GitHub
Skip to content

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Jun 5, 2025

We highly recommend using Node Streams in Node.js because it's much faster and it is less likely to cause issues when chained in things like compression algorithms that need explicit flushing which the Web Streams ecosystem doesn't have a good solution for. However, that said, people want to be able to use the worse option for various reasons.

The .edge builds aren't technically intended for Node.js. A Node.js environments needs to be patched in various ways to support it. It's also less optimal since it can't use Node.js exclusive features and have to use the lowest common denominator such as JS implementations instead of native.

This adds a Web Streams build of Fizz but exclusively for Node.js so that in it we can rely on Node.js modules. The main difference compared to Edge is that SSR now uses createHash from the "crypto" module and imports TextEncoder from "util". We use setImmediate instead of setTimeout.

The public API is just react-dom/server which in Node.js automatically imports react-dom/server.node which re-exports the legacy bundle, Node Streams bundle and Node Web Streams bundle. The main downside is if your bundler isn't smart to DCE this barrel file.

With Flight the difference is larger but that's a bigger lift.

@sebmarkbage sebmarkbage requested review from eps1lon and gnoff June 5, 2025 04:13
@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label Jun 5, 2025
@react-sizebot
Copy link

react-sizebot commented Jun 5, 2025

Comparing: 3705486...4735f9c

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB = 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 530.07 kB 530.07 kB = 93.57 kB 93.57 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 651.16 kB 651.16 kB = 114.70 kB 114.70 kB
facebook-www/ReactDOM-prod.classic.js = 676.11 kB 676.11 kB = 118.97 kB 118.97 kB
facebook-www/ReactDOM-prod.modern.js = 666.39 kB 666.39 kB = 117.36 kB 117.36 kB
oss-experimental/react-dom/cjs/react-dom-server.node-webstreams.development.js New file 0.00 kB 446.87 kB New file 0.00 kB 77.47 kB
oss-experimental/react-dom/cjs/react-dom-server.node-webstreams.production.js New file 0.00 kB 292.26 kB New file 0.00 kB 51.43 kB
oss-stable-semver/react-dom/cjs/react-dom-server.node-webstreams.development.js New file 0.00 kB 403.92 kB New file 0.00 kB 72.16 kB
oss-stable-semver/react-dom/cjs/react-dom-server.node-webstreams.production.js New file 0.00 kB 255.41 kB New file 0.00 kB 46.50 kB
oss-stable/react-dom/cjs/react-dom-server.node-webstreams.development.js New file 0.00 kB 403.99 kB New file 0.00 kB 72.21 kB
oss-stable/react-dom/cjs/react-dom-server.node-webstreams.production.js New file 0.00 kB 255.48 kB New file 0.00 kB 46.53 kB
oss-experimental/react-dom/static.node.js +63.71% 0.36 kB 0.59 kB +17.09% 0.20 kB 0.23 kB
oss-stable-semver/react-dom/static.node.js +63.71% 0.36 kB 0.59 kB +17.09% 0.20 kB 0.23 kB
oss-stable/react-dom/static.node.js +63.71% 0.36 kB 0.59 kB +17.09% 0.20 kB 0.23 kB
oss-experimental/react-dom/server.node.js +40.71% 0.62 kB 0.87 kB +16.67% 0.25 kB 0.29 kB
oss-stable-semver/react-dom/server.node.js +40.71% 0.62 kB 0.87 kB +16.67% 0.25 kB 0.29 kB
oss-stable/react-dom/server.node.js +40.71% 0.62 kB 0.87 kB +16.67% 0.25 kB 0.29 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-dom/cjs/react-dom-server.node-webstreams.development.js New file 0.00 kB 446.87 kB New file 0.00 kB 77.47 kB
oss-experimental/react-dom/cjs/react-dom-server.node-webstreams.production.js New file 0.00 kB 292.26 kB New file 0.00 kB 51.43 kB
oss-stable-semver/react-dom/cjs/react-dom-server.node-webstreams.development.js New file 0.00 kB 403.92 kB New file 0.00 kB 72.16 kB
oss-stable-semver/react-dom/cjs/react-dom-server.node-webstreams.production.js New file 0.00 kB 255.41 kB New file 0.00 kB 46.50 kB
oss-stable/react-dom/cjs/react-dom-server.node-webstreams.development.js New file 0.00 kB 403.99 kB New file 0.00 kB 72.21 kB
oss-stable/react-dom/cjs/react-dom-server.node-webstreams.production.js New file 0.00 kB 255.48 kB New file 0.00 kB 46.53 kB
oss-experimental/react-dom/static.node.js +63.71% 0.36 kB 0.59 kB +17.09% 0.20 kB 0.23 kB
oss-stable-semver/react-dom/static.node.js +63.71% 0.36 kB 0.59 kB +17.09% 0.20 kB 0.23 kB
oss-stable/react-dom/static.node.js +63.71% 0.36 kB 0.59 kB +17.09% 0.20 kB 0.23 kB
oss-experimental/react-dom/server.node.js +40.71% 0.62 kB 0.87 kB +16.67% 0.25 kB 0.29 kB
oss-stable-semver/react-dom/server.node.js +40.71% 0.62 kB 0.87 kB +16.67% 0.25 kB 0.29 kB
oss-stable/react-dom/server.node.js +40.71% 0.62 kB 0.87 kB +16.67% 0.25 kB 0.29 kB

Generated by 🚫 dangerJS against 4735f9c

export type BinaryChunk = Uint8Array;

export function scheduleWork(callback: () => void) {
setImmediate(callback);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a big one. The Edge build uses setTimeout which might not be as fast as setImmediate in Node but is in Edge environments.

Copy link
Collaborator

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

:feels-good:

@sebmarkbage sebmarkbage merged commit 93f1668 into facebook:main Jun 5, 2025
241 checks passed
sebmarkbage added a commit that referenced this pull request Jun 5, 2025
… for Webpack (#33442)

Like #33441 but for Flight.

This is just one of the many combinations needed. I'm just starting with
one.
sebmarkbage added a commit that referenced this pull request Jun 7, 2025
New take on #33441.

This uses a wrapper instead of a separate bundle.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants