Move useMemoCache hook to react/compiler-runtime (#28954)
Move useMemoCache hook to react/compiler-runtime For Meta-internal purposes, we keep the export on `react` itself to reduce churn.
Jan Kassens committed
Apr 30, 2024 at 12:00 UTC
4508873393058e86bed308b56e49ec883ece59d1
14 files changed
+61
-11
packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js
+1
-1
@@ -37,7 +37,7 @@ describe('ReactHooksInspectionIntegration', () => {
37
ReactDOM = require('react-dom');
38
act = require('internal-test-utils').act;
39
ReactDebugTools = require('react-debug-tools');
40
- useMemoCache = React.unstable_useMemoCache;
40
+ useMemoCache = require('react/compiler-runtime').c;
41
});
42
43
it('should inspect the current state of useState hooks', async () => {
packages/react-devtools-shell/src/app/InspectableElements/UseMemoCache.js
+2
-1
@@ -1,7 +1,8 @@
1
import * as React from 'react';
2
+import {c as useMemoCache} from 'react/compiler-runtime';
3
4
export default function UseMemoCache(): React.Node {
4
- React.unstable_useMemoCache(1);
5
+ useMemoCache(1);
6
7
return null;
8
}
packages/react-reconciler/src/__tests__/useMemoCache-test.js
+1
-1
@@ -27,8 +27,8 @@ describe('useMemoCache()', () => {
27
Scheduler = require('scheduler');
28
act = require('internal-test-utils').act;
29
assertLog = require('internal-test-utils').assertLog;
30
+ useMemoCache = require('react/compiler-runtime').c;
31
useState = React.useState;
31
- useMemoCache = React.unstable_useMemoCache;
32
MemoCacheSentinel = Symbol.for('react.memo_cache_sentinel');
33
34
class _ErrorBoundary extends React.Component {
packages/react/compiler-runtime.js
new
+10
@@ -0,0 +1,10 @@
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
+export {useMemoCache as c} from './src/ReactHooks';
packages/react/index.classic.fb.js
+8
-1
@@ -36,7 +36,6 @@ export {
36
unstable_SuspenseList,
37
unstable_getCacheForType,
38
unstable_useCacheRefresh,
39
- unstable_useMemoCache,
39
useId,
40
useCallback,
41
useContext,
@@ -57,4 +56,12 @@ export {
56
useActionState,
57
version,
58
} from './src/ReactClient';
59
+
60
export {jsx, jsxs, jsxDEV} from './src/jsx/ReactJSX';
61
+
62
+// export for backwards compatibility during upgrade
63
+export {useMemoCache as unstable_useMemoCache} from './src/ReactHooks';
64
+
65
+// export to match the name of the OSS function typically exported from
66
+// react/compiler-runtime
67
+export {useMemoCache as c} from './src/ReactHooks';
packages/react/index.experimental.js
-1
@@ -34,7 +34,6 @@ export {
34
unstable_getCacheForType,
35
unstable_SuspenseList,
36
unstable_useCacheRefresh,
37
- unstable_useMemoCache,
37
useId,
38
useCallback,
39
useContext,
packages/react/index.js
-1
@@ -57,7 +57,6 @@ export {
57
unstable_TracingMarker,
58
unstable_getCacheForType,
59
unstable_useCacheRefresh,
60
- unstable_useMemoCache,
60
useId,
61
useCallback,
62
useContext,
packages/react/index.modern.fb.js
+7
-1
@@ -36,7 +36,6 @@ export {
36
unstable_TracingMarker,
37
unstable_getCacheForType,
38
unstable_useCacheRefresh,
39
- unstable_useMemoCache,
39
useId,
40
useCallback,
41
useContext,
@@ -58,3 +57,10 @@ export {
57
version,
58
} from './src/ReactClient';
59
export {jsx, jsxs, jsxDEV} from './src/jsx/ReactJSX';
60
+
61
+// export for backwards compatibility during upgrade
62
+export {useMemoCache as unstable_useMemoCache} from './src/ReactHooks';
63
+
64
+// export to match the name of the OSS function typically exported from
65
+// react/compiler-runtime
66
+export {useMemoCache as c} from './src/ReactHooks';
packages/react/npm/compiler-runtime.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
+
8
+'use strict';
9
+
10
+if (process.env.NODE_ENV === 'production') {
11
+ module.exports = require('./cjs/react-compiler-runtime.production.js');
12
+} else {
13
+ module.exports = require('./cjs/react-compiler-runtime.development.js');
14
+}
packages/react/package.json
+5
@@ -13,6 +13,7 @@
13
"README.md",
14
"index.js",
15
"cjs/",
16
+ "compiler-runtime.js",
17
"jsx-runtime.js",
18
"jsx-runtime.react-server.js",
19
"jsx-dev-runtime.js",
@@ -34,6 +35,10 @@
35
"react-server": "./jsx-dev-runtime.react-server.js",
36
"default": "./jsx-dev-runtime.js"
37
},
38
+ "./compiler-runtime": {
39
+ "react-server": "./compiler-runtime.js",
40
+ "default": "./compiler-runtime.js"
41
+ },
42
"./src/*": "./src/*"
43
},
44
"repository": {
packages/react/src/ReactClient.js
-2
@@ -55,7 +55,6 @@ import {
55
useId,
56
useCacheRefresh,
57
use,
58
- useMemoCache,
58
useOptimistic,
59
useActionState,
60
} from './ReactHooks';
@@ -117,7 +116,6 @@ export {
116
getCacheForType as unstable_getCacheForType,
117
useCacheRefresh as unstable_useCacheRefresh,
118
use,
120
- useMemoCache as unstable_useMemoCache,
119
// enableScopeAPI
120
REACT_SCOPE_TYPE as unstable_Scope,
121
// enableTransitionTracing
packages/shared/ReactFeatureFlags.js
+1
-1
@@ -102,7 +102,7 @@ export const enableSuspenseAvoidThisFallbackFizz = false;
102
103
export const enableCPUSuspense = __EXPERIMENTAL__;
104
105
-// Enables unstable_useMemoCache hook, intended as a compilation target for
105
+// Enables useMemoCache hook, intended as a compilation target for
106
// auto-memoization.
107
export const enableUseMemoCacheHook = __EXPERIMENTAL__;
108
// Test this at Meta before enabling.
packages/shared/forks/ReactFeatureFlags.test-renderer.js
+1
-1
@@ -36,7 +36,7 @@ export const disableTextareaChildren = false;
36
export const enableSuspenseAvoidThisFallback = false;
37
export const enableSuspenseAvoidThisFallbackFizz = false;
38
export const enableCPUSuspense = false;
39
-export const enableUseMemoCacheHook = true;
39
+export const enableUseMemoCacheHook = __EXPERIMENTAL__;
40
export const enableNoCloningMemoCache = false;
41
export const enableUseEffectEventHook = false;
42
export const favorSafetyOverHydrationPerf = true;
scripts/rollup/bundles.js
+11
@@ -115,6 +115,17 @@ const bundles = [
115
externals: ['react', 'ReactNativeInternalFeatureFlags'],
116
},
117
118
+ /******* Compiler Runtime *******/
119
+ {
120
+ bundleTypes: [NODE_DEV, NODE_PROD, NODE_PROFILING],
121
+ moduleType: ISOMORPHIC,
122
+ entry: 'react/compiler-runtime',
123
+ global: 'CompilerRuntime',
124
+ minifyWithProdErrorCodes: true,
125
+ wrapWithModuleBoundaries: false,
126
+ externals: ['react'],
127
+ },
128
+
129
/******* React JSX Runtime React Server *******/
130
{
131
bundleTypes: [NODE_DEV, NODE_PROD],