Upgrade tests to use react/jsx-runtime (#28252)

Instead of createElement.

We should have done this when we initially released jsx-runtime but
better late than never. The general principle is that our tests should
be written using the most up-to-date idioms that we recommend for users,
except when explicitly testing an edge case or legacy behavior, like for
backwards compatibility.

Most of the diff is related to tweaking test output and isn't very
interesting.

I did have to workaround an issue related to component stacks. The
component stack logic depends on shared state that lives in the React
module. The problem is that most of our tests reset the React module
state and re-require a fresh instance of React, React DOM, etc. However,
the JSX runtime is not re-required because it's injected by the compiler
as a static import. This means its copy of the shared state is no longer
the same as the one used by React, causing any warning logged by the JSX
runtime to not include a component stack. (This same issue also breaks
string refs, but since we're removing those soon I'm not so concerned
about that.) The solution I went with for now is to mock the JSX runtime
with a proxy that re-requires the module on every function invocation. I
don't love this but it will have to do for now. What we should really do
is migrate our tests away from manually resetting the module state and
use import syntax instead.

DiffTrain build for commit https://github.com/facebook/react/commit/952aa74f8e45ed35ac6bf1de10ad5ed5410deac6.
This commit is contained in:
acdlite
2024-02-06 04:13:38 +00:00
parent 3d453eb1c2
commit 1727beceed
7 changed files with 9 additions and 9 deletions
@@ -25600,7 +25600,7 @@ if (__DEV__) {
return root;
}
var ReactVersion = "18.3.0-canary-2bc7d336a-20240205";
var ReactVersion = "18.3.0-canary-952aa74f8-20240205";
// Might add PROFILE later.
@@ -9150,7 +9150,7 @@ var devToolsConfig$jscomp$inline_1012 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-2bc7d336a-20240205",
version: "18.3.0-canary-952aa74f8-20240205",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1190 = {
@@ -9181,7 +9181,7 @@ var internals$jscomp$inline_1190 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-2bc7d336a-20240205"
reconcilerVersion: "18.3.0-canary-952aa74f8-20240205"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1191 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -9578,7 +9578,7 @@ var devToolsConfig$jscomp$inline_1054 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-2bc7d336a-20240205",
version: "18.3.0-canary-952aa74f8-20240205",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1231 = {
@@ -9609,7 +9609,7 @@ var internals$jscomp$inline_1231 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-2bc7d336a-20240205"
reconcilerVersion: "18.3.0-canary-952aa74f8-20240205"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1232 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -24,7 +24,7 @@ if (__DEV__) {
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var ReactVersion = "18.3.0-canary-2bc7d336a-20240205";
var ReactVersion = "18.3.0-canary-952aa74f8-20240205";
// ATTENTION
// When adding new symbols to this file,
@@ -543,4 +543,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-2bc7d336a-20240205";
exports.version = "18.3.0-canary-952aa74f8-20240205";
@@ -539,7 +539,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-2bc7d336a-20240205";
exports.version = "18.3.0-canary-952aa74f8-20240205";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
@@ -1 +1 @@
2bc7d336ae7db689699baeb1fffc2c03d8753ffe
952aa74f8e45ed35ac6bf1de10ad5ed5410deac6