Skip to content

Commit

Permalink
[rcr] Re-export useMemoCache in top level React namespace (#31139)
Browse files Browse the repository at this point in the history
In order to support using the compiler on versions of React prior to 19,
we need the ability to statically import `c` (aka useMemoCache) or
fallback to a polyfill supplied by `react-compiler-runtime` (note: this
is a separate npm package, not to be confused with
`react/compiler-runtime`, which is currently a part of react).

To do this we first need to re-export `useMemoCache` under the top level
React namespace again, which is additive and thus non-breaking. Doing so
allows `react-compiler-runtime` to statically either re-export
`React.__COMPILER_RUNTIME.c` or supply a polyfill, without the need for
a dynamic import which is finicky to support due to returning a promise.

In later PRs I will remove `react/compiler-runtime` and update the
compiler to emit imports to `react-compiler-runtime` instead.

DiffTrain build for [b78a7f2](b78a7f2)
  • Loading branch information
poteto committed Oct 7, 2024
1 parent 56bda35 commit 877636d
Show file tree
Hide file tree
Showing 34 changed files with 100 additions and 88 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d8c90fa48d3addefe4b805ec56a3c65e4ee39127
b78a7f2f35e554a8647c3262d7f392e68d06febc
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION_TRANSFORMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d8c90fa48d3addefe4b805ec56a3c65e4ee39127
b78a7f2f35e554a8647c3262d7f392e68d06febc
6 changes: 4 additions & 2 deletions compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,8 @@ __DEV__ &&
return queueMicrotask(callback);
});
}
: enqueueTask;
: enqueueTask,
ReactCompilerRuntime = { c: useMemoCache };
exports.Children = {
map: mapChildren,
forEach: function (children, forEachFunc, forEachContext) {
Expand Down Expand Up @@ -1403,6 +1404,7 @@ __DEV__ &&
exports.Suspense = REACT_SUSPENSE_TYPE;
exports.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE =
ReactSharedInternals;
exports.__COMPILER_RUNTIME = ReactCompilerRuntime;
exports.act = function (callback) {
var prevIsBatchingLegacy = disableLegacyMode
? !1
Expand Down Expand Up @@ -2000,7 +2002,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-www-classic-d8c90fa4-20241001";
exports.version = "19.0.0-www-classic-b78a7f2f-20241007";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
6 changes: 4 additions & 2 deletions compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,8 @@ __DEV__ &&
return queueMicrotask(callback);
});
}
: enqueueTask;
: enqueueTask,
ReactCompilerRuntime = { c: useMemoCache };
exports.Children = {
map: mapChildren,
forEach: function (children, forEachFunc, forEachContext) {
Expand Down Expand Up @@ -1399,6 +1400,7 @@ __DEV__ &&
exports.Suspense = REACT_SUSPENSE_TYPE;
exports.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE =
ReactSharedInternals;
exports.__COMPILER_RUNTIME = ReactCompilerRuntime;
exports.act = function (callback) {
var prevActQueue = ReactSharedInternals.actQueue,
prevActScopeDepth = actScopeDepth;
Expand Down Expand Up @@ -1980,7 +1982,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-www-modern-d8c90fa4-20241001";
exports.version = "19.0.0-www-modern-b78a7f2f-20241007";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
4 changes: 3 additions & 1 deletion compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ var reportGlobalError =
console.error(error);
};
function noop() {}
var ReactCompilerRuntime = { c: useMemoCache };
exports.Children = {
map: mapChildren,
forEach: function (children, forEachFunc, forEachContext) {
Expand Down Expand Up @@ -436,6 +437,7 @@ exports.StrictMode = REACT_STRICT_MODE_TYPE;
exports.Suspense = REACT_SUSPENSE_TYPE;
exports.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE =
ReactSharedInternals;
exports.__COMPILER_RUNTIME = ReactCompilerRuntime;
exports.act = function () {
throw Error("act(...) is not supported in production builds of React.");
};
Expand Down Expand Up @@ -665,4 +667,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-d8c90fa4-20241001";
exports.version = "19.0.0-www-classic-b78a7f2f-20241007";
4 changes: 3 additions & 1 deletion compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ var reportGlobalError =
console.error(error);
};
function noop() {}
var ReactCompilerRuntime = { c: useMemoCache };
exports.Children = {
map: mapChildren,
forEach: function (children, forEachFunc, forEachContext) {
Expand Down Expand Up @@ -436,6 +437,7 @@ exports.StrictMode = REACT_STRICT_MODE_TYPE;
exports.Suspense = REACT_SUSPENSE_TYPE;
exports.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE =
ReactSharedInternals;
exports.__COMPILER_RUNTIME = ReactCompilerRuntime;
exports.act = function () {
throw Error("act(...) is not supported in production builds of React.");
};
Expand Down Expand Up @@ -665,4 +667,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-modern-d8c90fa4-20241001";
exports.version = "19.0.0-www-modern-b78a7f2f-20241007";
4 changes: 3 additions & 1 deletion compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ var reportGlobalError =
console.error(error);
};
function noop() {}
var ReactCompilerRuntime = { c: useMemoCache };
exports.Children = {
map: mapChildren,
forEach: function (children, forEachFunc, forEachContext) {
Expand Down Expand Up @@ -440,6 +441,7 @@ exports.StrictMode = REACT_STRICT_MODE_TYPE;
exports.Suspense = REACT_SUSPENSE_TYPE;
exports.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE =
ReactSharedInternals;
exports.__COMPILER_RUNTIME = ReactCompilerRuntime;
exports.act = function () {
throw Error("act(...) is not supported in production builds of React.");
};
Expand Down Expand Up @@ -669,7 +671,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-d8c90fa4-20241001";
exports.version = "19.0.0-www-classic-b78a7f2f-20241007";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
4 changes: 3 additions & 1 deletion compiled/facebook-www/React-profiling.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ var reportGlobalError =
console.error(error);
};
function noop() {}
var ReactCompilerRuntime = { c: useMemoCache };
exports.Children = {
map: mapChildren,
forEach: function (children, forEachFunc, forEachContext) {
Expand Down Expand Up @@ -440,6 +441,7 @@ exports.StrictMode = REACT_STRICT_MODE_TYPE;
exports.Suspense = REACT_SUSPENSE_TYPE;
exports.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE =
ReactSharedInternals;
exports.__COMPILER_RUNTIME = ReactCompilerRuntime;
exports.act = function () {
throw Error("act(...) is not supported in production builds of React.");
};
Expand Down Expand Up @@ -669,7 +671,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-modern-d8c90fa4-20241001";
exports.version = "19.0.0-www-modern-b78a7f2f-20241007";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
6 changes: 3 additions & 3 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -17014,11 +17014,11 @@ __DEV__ &&
(function () {
var internals = {
bundleType: 1,
version: "19.0.0-www-classic-d8c90fa4-20241001",
version: "19.0.0-www-classic-b78a7f2f-20241007",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getInstanceFromNode,
reconcilerVersion: "19.0.0-www-classic-d8c90fa4-20241001"
reconcilerVersion: "19.0.0-www-classic-b78a7f2f-20241007"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -17052,7 +17052,7 @@ __DEV__ &&
exports.Shape = Shape;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.0.0-www-classic-d8c90fa4-20241001";
exports.version = "19.0.0-www-classic-b78a7f2f-20241007";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
6 changes: 3 additions & 3 deletions compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -16457,11 +16457,11 @@ __DEV__ &&
(function () {
var internals = {
bundleType: 1,
version: "19.0.0-www-modern-d8c90fa4-20241001",
version: "19.0.0-www-modern-b78a7f2f-20241007",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getInstanceFromNode,
reconcilerVersion: "19.0.0-www-modern-d8c90fa4-20241001"
reconcilerVersion: "19.0.0-www-modern-b78a7f2f-20241007"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -16495,7 +16495,7 @@ __DEV__ &&
exports.Shape = Shape;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.0.0-www-modern-d8c90fa4-20241001";
exports.version = "19.0.0-www-modern-b78a7f2f-20241007";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
6 changes: 3 additions & 3 deletions compiled/facebook-www/ReactART-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -10826,13 +10826,13 @@ var slice = Array.prototype.slice,
})(React.Component);
var internals$jscomp$inline_1467 = {
bundleType: 0,
version: "19.0.0-www-classic-d8c90fa4-20241001",
version: "19.0.0-www-classic-b78a7f2f-20241007",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: function () {
return null;
},
reconcilerVersion: "19.0.0-www-classic-d8c90fa4-20241001"
reconcilerVersion: "19.0.0-www-classic-b78a7f2f-20241007"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1468 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand All @@ -10858,4 +10858,4 @@ exports.RadialGradient = RadialGradient;
exports.Shape = TYPES.SHAPE;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.0.0-www-classic-d8c90fa4-20241001";
exports.version = "19.0.0-www-classic-b78a7f2f-20241007";
6 changes: 3 additions & 3 deletions compiled/facebook-www/ReactART-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -10337,13 +10337,13 @@ var slice = Array.prototype.slice,
})(React.Component);
var internals$jscomp$inline_1459 = {
bundleType: 0,
version: "19.0.0-www-modern-d8c90fa4-20241001",
version: "19.0.0-www-modern-b78a7f2f-20241007",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: function () {
return null;
},
reconcilerVersion: "19.0.0-www-modern-d8c90fa4-20241001"
reconcilerVersion: "19.0.0-www-modern-b78a7f2f-20241007"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1460 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand All @@ -10369,4 +10369,4 @@ exports.RadialGradient = RadialGradient;
exports.Shape = TYPES.SHAPE;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.0.0-www-modern-d8c90fa4-20241001";
exports.version = "19.0.0-www-modern-b78a7f2f-20241007";
10 changes: 5 additions & 5 deletions compiled/facebook-www/ReactDOM-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -27771,11 +27771,11 @@ __DEV__ &&
: flushSyncErrorInBuildsThatSupportLegacyMode;
(function () {
var isomorphicReactPackageVersion = React.version;
if ("19.0.0-www-classic-d8c90fa4-20241001" !== isomorphicReactPackageVersion)
if ("19.0.0-www-classic-b78a7f2f-20241007" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-dom: 19.0.0-www-classic-d8c90fa4-20241001\nLearn more: https://react.dev/warnings/version-mismatch")
"\n - react-dom: 19.0.0-www-classic-b78a7f2f-20241007\nLearn more: https://react.dev/warnings/version-mismatch")
);
})();
("function" === typeof Map &&
Expand Down Expand Up @@ -27819,11 +27819,11 @@ __DEV__ &&
!(function () {
var internals = {
bundleType: 1,
version: "19.0.0-www-classic-d8c90fa4-20241001",
version: "19.0.0-www-classic-b78a7f2f-20241007",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getClosestInstanceFromNode,
reconcilerVersion: "19.0.0-www-classic-d8c90fa4-20241001"
reconcilerVersion: "19.0.0-www-classic-b78a7f2f-20241007"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -28476,7 +28476,7 @@ __DEV__ &&
exports.useFormStatus = function () {
return resolveDispatcher().useHostTransitionStatus();
};
exports.version = "19.0.0-www-classic-d8c90fa4-20241001";
exports.version = "19.0.0-www-classic-b78a7f2f-20241007";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
10 changes: 5 additions & 5 deletions compiled/facebook-www/ReactDOM-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -26885,11 +26885,11 @@ __DEV__ &&
return_targetInst = null;
(function () {
var isomorphicReactPackageVersion = React.version;
if ("19.0.0-www-modern-d8c90fa4-20241001" !== isomorphicReactPackageVersion)
if ("19.0.0-www-modern-b78a7f2f-20241007" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-dom: 19.0.0-www-modern-d8c90fa4-20241001\nLearn more: https://react.dev/warnings/version-mismatch")
"\n - react-dom: 19.0.0-www-modern-b78a7f2f-20241007\nLearn more: https://react.dev/warnings/version-mismatch")
);
})();
("function" === typeof Map &&
Expand Down Expand Up @@ -26932,11 +26932,11 @@ __DEV__ &&
!(function () {
var internals = {
bundleType: 1,
version: "19.0.0-www-modern-d8c90fa4-20241001",
version: "19.0.0-www-modern-b78a7f2f-20241007",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getClosestInstanceFromNode,
reconcilerVersion: "19.0.0-www-modern-d8c90fa4-20241001"
reconcilerVersion: "19.0.0-www-modern-b78a7f2f-20241007"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -27541,7 +27541,7 @@ __DEV__ &&
exports.useFormStatus = function () {
return resolveDispatcher().useHostTransitionStatus();
};
exports.version = "19.0.0-www-modern-d8c90fa4-20241001";
exports.version = "19.0.0-www-modern-b78a7f2f-20241007";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
10 changes: 5 additions & 5 deletions compiled/facebook-www/ReactDOM-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -17412,14 +17412,14 @@ function getCrossOriginStringAs(as, input) {
}
var isomorphicReactPackageVersion$jscomp$inline_1774 = React.version;
if (
"19.0.0-www-classic-d8c90fa4-20241001" !==
"19.0.0-www-classic-b78a7f2f-20241007" !==
isomorphicReactPackageVersion$jscomp$inline_1774
)
throw Error(
formatProdErrorMessage(
527,
isomorphicReactPackageVersion$jscomp$inline_1774,
"19.0.0-www-classic-d8c90fa4-20241001"
"19.0.0-www-classic-b78a7f2f-20241007"
)
);
function flushSyncFromReconciler(fn) {
Expand Down Expand Up @@ -17464,11 +17464,11 @@ Internals.Events = [
];
var internals$jscomp$inline_2287 = {
bundleType: 0,
version: "19.0.0-www-classic-d8c90fa4-20241001",
version: "19.0.0-www-classic-b78a7f2f-20241007",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getClosestInstanceFromNode,
reconcilerVersion: "19.0.0-www-classic-d8c90fa4-20241001"
reconcilerVersion: "19.0.0-www-classic-b78a7f2f-20241007"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2288 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down Expand Up @@ -17924,4 +17924,4 @@ exports.useFormState = function (action, initialState, permalink) {
exports.useFormStatus = function () {
return ReactSharedInternals.H.useHostTransitionStatus();
};
exports.version = "19.0.0-www-classic-d8c90fa4-20241001";
exports.version = "19.0.0-www-classic-b78a7f2f-20241007";
10 changes: 5 additions & 5 deletions compiled/facebook-www/ReactDOM-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -16780,14 +16780,14 @@ function getCrossOriginStringAs(as, input) {
}
var isomorphicReactPackageVersion$jscomp$inline_1745 = React.version;
if (
"19.0.0-www-modern-d8c90fa4-20241001" !==
"19.0.0-www-modern-b78a7f2f-20241007" !==
isomorphicReactPackageVersion$jscomp$inline_1745
)
throw Error(
formatProdErrorMessage(
527,
isomorphicReactPackageVersion$jscomp$inline_1745,
"19.0.0-www-modern-d8c90fa4-20241001"
"19.0.0-www-modern-b78a7f2f-20241007"
)
);
Internals.findDOMNode = function (componentOrElement) {
Expand All @@ -16805,11 +16805,11 @@ Internals.Events = [
];
var internals$jscomp$inline_2278 = {
bundleType: 0,
version: "19.0.0-www-modern-d8c90fa4-20241001",
version: "19.0.0-www-modern-b78a7f2f-20241007",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getClosestInstanceFromNode,
reconcilerVersion: "19.0.0-www-modern-d8c90fa4-20241001"
reconcilerVersion: "19.0.0-www-modern-b78a7f2f-20241007"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2279 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down Expand Up @@ -17172,4 +17172,4 @@ exports.useFormState = function (action, initialState, permalink) {
exports.useFormStatus = function () {
return ReactSharedInternals.H.useHostTransitionStatus();
};
exports.version = "19.0.0-www-modern-d8c90fa4-20241001";
exports.version = "19.0.0-www-modern-b78a7f2f-20241007";
Loading

0 comments on commit 877636d

Please sign in to comment.