Skip to content

Commit

Permalink
[Tests][Fizz] Better HTML parsing behavior for Fizz tests (#26570)
Browse files Browse the repository at this point in the history
In anticipation of making Fiber use the document global for dispatching
Float methods that arrive from Flight I needed to update some tests that
commonly recreated the JSDOM instance after importing react.

This change updates a few tests to only create JSDOM once per test,
before importing react-dom/client.

Additionally the current act implementation for server streaming did not
adequately model streaming semantics so I rewrite the act implementation
in a way that better mirrors how a browser would parse incoming HTML.

The new act implementation does the following

1. the first time it processes meaningful streamed content it figures
out whether it is rendering into the existing document container or if
it needs to reset the document. this is based on whether the streamed
content contains tags `<html>` or `<body>` etc...
2. Once the streaming container is set it will typically continue to
stream into that container for future calls to act. The exception is if
the streaming container is the `<head>` in which case it will switch to
streaming into the body once it receives a `<body>` tag.

This means for tests that render something like a `<div>...</div>` it
will naturally stream into the default `<div id="container">...` and for
tests that render a full document the HTML will parse like a real
browser would (with some very minor edge case differences)

I also refactored the way we move nodes from buffered content into the
document and execute any scripts we find. Previously we were using
window.eval and I switched this to just setting the external script
content as script text. Additionally the nonce logic is reworked to be a
bit simpler.

DiffTrain build for commit e5708b3.
  • Loading branch information
gnoff committed Apr 20, 2023
1 parent 12d760c commit 73fddfc
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23859,7 +23859,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-next-d73d7d590-20230420";
var ReactVersion = "18.3.0-next-e5708b3ea-20230420";

// Might add PROFILE later.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8599,7 +8599,7 @@ var devToolsConfig$jscomp$inline_1021 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-next-d73d7d590-20230420",
version: "18.3.0-next-e5708b3ea-20230420",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1206 = {
Expand Down Expand Up @@ -8630,7 +8630,7 @@ var internals$jscomp$inline_1206 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-d73d7d590-20230420"
reconcilerVersion: "18.3.0-next-e5708b3ea-20230420"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1207 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9025,7 +9025,7 @@ var devToolsConfig$jscomp$inline_1063 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-next-d73d7d590-20230420",
version: "18.3.0-next-e5708b3ea-20230420",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1247 = {
Expand Down Expand Up @@ -9056,7 +9056,7 @@ var internals$jscomp$inline_1247 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-d73d7d590-20230420"
reconcilerVersion: "18.3.0-next-e5708b3ea-20230420"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1248 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-next-d73d7d590-20230420";
var ReactVersion = "18.3.0-next-e5708b3ea-20230420";

// ATTENTION
// When adding new symbols to this file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,4 +639,4 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-next-d73d7d590-20230420";
exports.version = "18.3.0-next-e5708b3ea-20230420";
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-next-d73d7d590-20230420";
exports.version = "18.3.0-next-e5708b3ea-20230420";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d73d7d59086218b0fa42d0a79c32a0365952650b
e5708b3ea9190c1285c9081ff338e46be9ff39bc
Original file line number Diff line number Diff line change
Expand Up @@ -27169,7 +27169,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-next-d73d7d590-20230420";
var ReactVersion = "18.3.0-next-e5708b3ea-20230420";

function createPortal$1(
children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9470,7 +9470,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1045 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "18.3.0-next-d73d7d590-20230420",
version: "18.3.0-next-e5708b3ea-20230420",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
Expand Down Expand Up @@ -9512,7 +9512,7 @@ var internals$jscomp$inline_1276 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-d73d7d590-20230420"
reconcilerVersion: "18.3.0-next-e5708b3ea-20230420"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1277 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10179,7 +10179,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1123 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "18.3.0-next-d73d7d590-20230420",
version: "18.3.0-next-e5708b3ea-20230420",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
Expand Down Expand Up @@ -10234,7 +10234,7 @@ var roots = new Map(),
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-d73d7d590-20230420"
reconcilerVersion: "18.3.0-next-e5708b3ea-20230420"
});
exports.createPortal = function (children, containerTag) {
return createPortal$1(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27682,7 +27682,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-next-d73d7d590-20230420";
var ReactVersion = "18.3.0-next-e5708b3ea-20230420";

function createPortal$1(
children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9729,7 +9729,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1100 = {
findFiberByHostInstance: getInstanceFromTag,
bundleType: 0,
version: "18.3.0-next-d73d7d590-20230420",
version: "18.3.0-next-e5708b3ea-20230420",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
Expand Down Expand Up @@ -9771,7 +9771,7 @@ var internals$jscomp$inline_1345 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-d73d7d590-20230420"
reconcilerVersion: "18.3.0-next-e5708b3ea-20230420"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1346 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10438,7 +10438,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1178 = {
findFiberByHostInstance: getInstanceFromTag,
bundleType: 0,
version: "18.3.0-next-d73d7d590-20230420",
version: "18.3.0-next-e5708b3ea-20230420",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
Expand Down Expand Up @@ -10493,7 +10493,7 @@ var roots = new Map(),
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-d73d7d590-20230420"
reconcilerVersion: "18.3.0-next-e5708b3ea-20230420"
});
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {
computeComponentStackForErrorReporting: function (reactTag) {
Expand Down

0 comments on commit 73fddfc

Please sign in to comment.