Skip to content

Commit

Permalink
useFormState: Only emit markers if postback state is provided (#27374)
Browse files Browse the repository at this point in the history
This is an optimization where useFormState will only emit extra comment
markers if a form state is passed at the root. If no state is passed, we
don't need to emit anything because none of the hooks will match.

DiffTrain build for [d6dcad6](d6dcad6)
  • Loading branch information
acdlite committed Sep 14, 2023
1 parent 97bcd7f commit 0a7bf73
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
caa716d50bdeef3a1ac5e3e0cfcc14f4d91f2028
d6dcad6a8beaeec0513a9851d1e0fe1181932360
9 changes: 4 additions & 5 deletions compiled/facebook-www/ReactDOMServer-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (__DEV__) {
var React = require("react");
var ReactDOM = require("react-dom");

var ReactVersion = "18.3.0-www-classic-360a070f";
var ReactVersion = "18.3.0-www-classic-a7988d89";

// This refers to a WWW module.
var warningWWW = require("warning");
Expand Down Expand Up @@ -10392,11 +10392,10 @@ function finishFunctionComponent(
) {
var didEmitFormStateMarkers = false;

if (formStateCount !== 0) {
if (formStateCount !== 0 && request.formState !== null) {
// For each useFormState hook, emit a marker that indicates whether we
// rendered using the form state passed at the root.
// TODO: As an optimization, Fizz should only emit these markers if form
// state is passed at the root.
// rendered using the form state passed at the root. We only emit these
// markers if form state is passed at the root.
var segment = task.blockedSegment;

if (segment === null);
Expand Down
9 changes: 4 additions & 5 deletions compiled/facebook-www/ReactDOMServer-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (__DEV__) {
var React = require("react");
var ReactDOM = require("react-dom");

var ReactVersion = "18.3.0-www-modern-b814d906";
var ReactVersion = "18.3.0-www-modern-de2d6098";

// This refers to a WWW module.
var warningWWW = require("warning");
Expand Down Expand Up @@ -10140,11 +10140,10 @@ function finishFunctionComponent(
) {
var didEmitFormStateMarkers = false;

if (formStateCount !== 0) {
if (formStateCount !== 0 && request.formState !== null) {
// For each useFormState hook, emit a marker that indicates whether we
// rendered using the form state passed at the root.
// TODO: As an optimization, Fizz should only emit these markers if form
// state is passed at the root.
// rendered using the form state passed at the root. We only emit these
// markers if form state is passed at the root.
var segment = task.blockedSegment;

if (segment === null);
Expand Down
4 changes: 2 additions & 2 deletions compiled/facebook-www/ReactDOMServer-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3063,7 +3063,7 @@ function finishFunctionComponent(
formStateMatchingIndex
) {
var didEmitFormStateMarkers = !1;
if (0 !== formStateCount) {
if (0 !== formStateCount && null !== request.formState) {
var segment = task.blockedSegment;
if (null !== segment) {
didEmitFormStateMarkers = !0;
Expand Down Expand Up @@ -4556,4 +4556,4 @@ exports.renderToString = function (children, options) {
'The server used "renderToString" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to "renderToReadableStream" which supports Suspense on the server'
);
};
exports.version = "18.3.0-www-classic-f04a97ef";
exports.version = "18.3.0-www-classic-5dc27933";
4 changes: 2 additions & 2 deletions compiled/facebook-www/ReactDOMServer-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -3055,7 +3055,7 @@ function finishFunctionComponent(
formStateMatchingIndex
) {
var didEmitFormStateMarkers = !1;
if (0 !== formStateCount) {
if (0 !== formStateCount && null !== request.formState) {
var segment = task.blockedSegment;
if (null !== segment) {
didEmitFormStateMarkers = !0;
Expand Down Expand Up @@ -4523,4 +4523,4 @@ exports.renderToString = function (children, options) {
'The server used "renderToString" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to "renderToReadableStream" which supports Suspense on the server'
);
};
exports.version = "18.3.0-www-modern-b31a402c";
exports.version = "18.3.0-www-modern-a538c776";
7 changes: 3 additions & 4 deletions compiled/facebook-www/ReactDOMServerStreaming-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -10043,11 +10043,10 @@ function finishFunctionComponent(
) {
var didEmitFormStateMarkers = false;

if (formStateCount !== 0) {
if (formStateCount !== 0 && request.formState !== null) {
// For each useFormState hook, emit a marker that indicates whether we
// rendered using the form state passed at the root.
// TODO: As an optimization, Fizz should only emit these markers if form
// state is passed at the root.
// rendered using the form state passed at the root. We only emit these
// markers if form state is passed at the root.
var segment = task.blockedSegment;

if (segment === null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2849,7 +2849,7 @@ function finishFunctionComponent(
formStateMatchingIndex
) {
var didEmitFormStateMarkers = !1;
if (0 !== formStateCount) {
if (0 !== formStateCount && null !== request.formState) {
var segment = task.blockedSegment;
if (null !== segment) {
didEmitFormStateMarkers = !0;
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/ReactTestRenderer-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -24360,7 +24360,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-modern-f5e6bf9d";
var ReactVersion = "18.3.0-www-modern-fa8b400b";

// Might add PROFILE later.

Expand Down

0 comments on commit 0a7bf73

Please sign in to comment.