From ff6e098a4bba0020a70e97dece5b7da374c534b8 Mon Sep 17 00:00:00 2001 From: sebmarkbage Date: Tue, 22 Aug 2023 19:26:27 +0000 Subject: [PATCH] [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. DiffTrain build for [31034b6de73c7cd9093e92a34e384d84c082aa4e](https://github.com/facebook/react/commit/31034b6de73c7cd9093e92a34e384d84c082aa4e) --- compiled/facebook-www/REVISION | 2 +- .../ReactDOMServer-dev.classic.js | 808 ++++++++-------- .../facebook-www/ReactDOMServer-dev.modern.js | 808 ++++++++-------- .../ReactDOMServer-prod.classic.js | 899 +++++++++++------- .../ReactDOMServer-prod.modern.js | 899 +++++++++++------- .../ReactDOMServerStreaming-dev.modern.js | 720 +++++++------- .../ReactDOMServerStreaming-prod.modern.js | 808 ++++++++-------- 7 files changed, 2726 insertions(+), 2218 deletions(-) diff --git a/compiled/facebook-www/REVISION b/compiled/facebook-www/REVISION index 6e25073f77..9fcd94f1a6 100644 --- a/compiled/facebook-www/REVISION +++ b/compiled/facebook-www/REVISION @@ -1 +1 @@ -86198b923199224b60533952b636348bb0484a6d +31034b6de73c7cd9093e92a34e384d84c082aa4e diff --git a/compiled/facebook-www/ReactDOMServer-dev.classic.js b/compiled/facebook-www/ReactDOMServer-dev.classic.js index 62e44b8594..0f108839fd 100644 --- a/compiled/facebook-www/ReactDOMServer-dev.classic.js +++ b/compiled/facebook-www/ReactDOMServer-dev.classic.js @@ -19,7 +19,7 @@ if (__DEV__) { var React = require("react"); var ReactDOM = require("react-dom"); -var ReactVersion = "18.3.0-www-classic-2d41a773"; +var ReactVersion = "18.3.0-www-classic-dcbc1f0e"; // This refers to a WWW module. var warningWWW = require("warning"); @@ -1895,6 +1895,10 @@ var SentClientRenderFunction = var SentStyleInsertionFunction = /* */ 8; +// This cannot be resumed and therefore should only contain things that are +// temporary working state or are never used in the prerender pass. +// Per response, global state that is not contextual to the rendering subtree. +// This is resumable and therefore should be serializable. var dataElementQuotedEnd = stringToPrecomputedChunk('">'); var startInlineScript = stringToPrecomputedChunk("