mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
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](https://github.com/facebook/react/pull/33388) and have to use [the lowest common denominator](https://github.com/facebook/react/pull/27399) 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.
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
// This file is only used for tests.
|
|
// It lazily loads the implementation so that we get the correct set of host configs.
|
|
|
|
import ReactVersion from 'shared/ReactVersion';
|
|
export {ReactVersion as version};
|
|
|
|
export function renderToString() {
|
|
return require('./src/server/ReactDOMLegacyServerNode').renderToString.apply(
|
|
this,
|
|
arguments,
|
|
);
|
|
}
|
|
export function renderToStaticMarkup() {
|
|
return require('./src/server/ReactDOMLegacyServerNode').renderToStaticMarkup.apply(
|
|
this,
|
|
arguments,
|
|
);
|
|
}
|
|
|
|
export function prerenderToNodeStream() {
|
|
return require('./src/server/react-dom-server.node').prerenderToNodeStream.apply(
|
|
this,
|
|
arguments,
|
|
);
|
|
}
|
|
|
|
export function resumeAndPrerenderToNodeStream() {
|
|
return require('./src/server/react-dom-server.node').resumeAndPrerenderToNodeStream.apply(
|
|
this,
|
|
arguments,
|
|
);
|
|
}
|
|
|
|
export function prerender() {
|
|
return require('./src/server/react-dom-server.node-webstreams').prerender.apply(
|
|
this,
|
|
arguments,
|
|
);
|
|
}
|
|
|
|
export function resumeAndPrerender() {
|
|
return require('./src/server/react-dom-server.node-webstreams').resumeAndPrerender.apply(
|
|
this,
|
|
arguments,
|
|
);
|
|
}
|