@samitouri / QOS-React-1 / commits / b78a7f2f35

[rcr] Re-export useMemoCache in top level React namespace (#31139)

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.

lauren committed Oct 7, 2024 at 16:25 UTC b78a7f2f35e554a8647c3262d7f392e68d06febc
7 files changed +21
packages/react/index.development.js
+1
@@ -30,6 +30,7 @@ export type ChildrenArray<+T> = $ReadOnlyArray<ChildrenArray<T>> | T;
30 // We can't use export * from in Flow for some reason.
31 export {
32 __CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
33 + __COMPILER_RUNTIME,
34 Children,
35 Component,
36 Fragment,
packages/react/index.experimental.development.js
+1
@@ -9,6 +9,7 @@
9
10 export {
11 __CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
12 + __COMPILER_RUNTIME,
13 Children,
14 Component,
15 Fragment,
packages/react/index.experimental.js
+1
@@ -9,6 +9,7 @@
9
10 export {
11 __CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
12 + __COMPILER_RUNTIME,
13 Children,
14 Component,
15 Fragment,
packages/react/index.fb.js
+1
@@ -9,6 +9,7 @@
9
10 export {
11 __CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
12 + __COMPILER_RUNTIME,
13 act,
14 cache,
15 Children,
packages/react/index.js
+1
@@ -31,6 +31,7 @@ export type ChildrenArray<+T> = $ReadOnlyArray<ChildrenArray<T>> | T;
31 // We can't use export * from in Flow for some reason.
32 export {
33 __CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
34 + __COMPILER_RUNTIME,
35 Children,
36 Component,
37 Fragment,
packages/react/src/ReactClient.js
+2
@@ -63,6 +63,7 @@ import ReactSharedInternals from './ReactSharedInternalsClient';
63 import {startTransition} from './ReactStartTransition';
64 import {act} from './ReactAct';
65 import {captureOwnerStack} from './ReactOwnerStack';
66 +import ReactCompilerRuntime from './ReactCompilerRuntime';
67
68 const Children = {
69 map,
@@ -109,6 +110,7 @@ export {
110 isValidElement,
111 ReactVersion as version,
112 ReactSharedInternals as __CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
113 + ReactCompilerRuntime as __COMPILER_RUNTIME,
114 // Concurrent Mode
115 useTransition,
116 startTransition,
packages/react/src/ReactCompilerRuntime.js new
+14
@@ -0,0 +1,14 @@
1 +/**
2 + * Copyright (c) Meta Platforms, Inc. and affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + *
7 + * @flow
8 + */
9 +
10 +import {useMemoCache} from './ReactHooks';
11 +
12 +export default {
13 + c: useMemoCache,
14 +};