Skip to content

Commit b78a7f2

Browse files
authored
[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.
1 parent 68d59d4 commit b78a7f2

7 files changed

+21
-0
lines changed

packages/react/index.development.js

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type ChildrenArray<+T> = $ReadOnlyArray<ChildrenArray<T>> | T;
3030
// We can't use export * from in Flow for some reason.
3131
export {
3232
__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
33+
__COMPILER_RUNTIME,
3334
Children,
3435
Component,
3536
Fragment,

packages/react/index.experimental.development.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
export {
1111
__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
12+
__COMPILER_RUNTIME,
1213
Children,
1314
Component,
1415
Fragment,

packages/react/index.experimental.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
export {
1111
__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
12+
__COMPILER_RUNTIME,
1213
Children,
1314
Component,
1415
Fragment,

packages/react/index.fb.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
export {
1111
__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
12+
__COMPILER_RUNTIME,
1213
act,
1314
cache,
1415
Children,

packages/react/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export type ChildrenArray<+T> = $ReadOnlyArray<ChildrenArray<T>> | T;
3131
// We can't use export * from in Flow for some reason.
3232
export {
3333
__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
34+
__COMPILER_RUNTIME,
3435
Children,
3536
Component,
3637
Fragment,

packages/react/src/ReactClient.js

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import ReactSharedInternals from './ReactSharedInternalsClient';
6363
import {startTransition} from './ReactStartTransition';
6464
import {act} from './ReactAct';
6565
import {captureOwnerStack} from './ReactOwnerStack';
66+
import ReactCompilerRuntime from './ReactCompilerRuntime';
6667

6768
const Children = {
6869
map,
@@ -109,6 +110,7 @@ export {
109110
isValidElement,
110111
ReactVersion as version,
111112
ReactSharedInternals as __CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
113+
ReactCompilerRuntime as __COMPILER_RUNTIME,
112114
// Concurrent Mode
113115
useTransition,
114116
startTransition,
+14
Original file line numberDiff line numberDiff line change
@@ -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+
};

0 commit comments

Comments
 (0)