react/packages/react-dom/server.node.js
Sebastian Markbåge 31034b6de7
[Fizz] Split ResponseState/Resources into RenderState/ResumableState (#27268)
This exposes a `resume()` API to go with the `prerender()` (only in
experimental). It doesn't work yet since we don't yet emit the postponed
state so not yet tested.

The main thing this does is rename ResponseState->RenderState and
Resources->ResumableState. We separated out resources into a separate
concept preemptively since it seemed like separate enough but probably
doesn't warrant being a separate concept. The result is that we have a
per RenderState in the Config which is really just temporary state and
things that must be flushed completely in the prerender. Most things
should be ResumableState.

Most options are specified in the `prerender()` and transferred into the
`resume()` but certain options that are unique per request can't be.
Notably `nonce` is special. This means that bootstrap scripts and
external runtime can't use `nonce` in this mode. They need to have a CSP
configured to deal with external scripts, but not inline.

We need to be able to restore state of things that we've already emitted
in the prerender. We could have separate snapshot/restore methods that
does this work when it happens but that means we have to explicitly do
that work. This design is trying to keep to the principle that we just
work with resumable data structures instead so that we're designing for
it with every feature. It also makes restoring faster since it's just
straight into the data structure.

This is not yet a serializable format. That can be done in a follow up.

We also need to vet that each step makes sense. Notably stylesToHoist is
a bit unclear how it'll work.
2023-08-22 15:21:36 -04:00

52 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 renderToNodeStream() {
return require('./src/server/ReactDOMLegacyServerNode').renderToNodeStream.apply(
this,
arguments,
);
}
export function renderToStaticNodeStream() {
return require('./src/server/ReactDOMLegacyServerNode').renderToStaticNodeStream.apply(
this,
arguments,
);
}
export function renderToPipeableStream() {
return require('./src/server/react-dom-server.node').renderToPipeableStream.apply(
this,
arguments,
);
}
export function resume() {
return require('./src/server/react-dom-server.node').resume.apply(
this,
arguments,
);
}