Skip to content

Commit 4508873

Browse files
authored
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.
1 parent d779eba commit 4508873

File tree

14 files changed

+61
-11
lines changed

14 files changed

+61
-11
lines changed

packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('ReactHooksInspectionIntegration', () => {
3737
ReactDOM = require('react-dom');
3838
act = require('internal-test-utils').act;
3939
ReactDebugTools = require('react-debug-tools');
40-
useMemoCache = React.unstable_useMemoCache;
40+
useMemoCache = require('react/compiler-runtime').c;
4141
});
4242

4343
it('should inspect the current state of useState hooks', async () => {
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as React from 'react';
2+
import {c as useMemoCache} from 'react/compiler-runtime';
23

34
export default function UseMemoCache(): React.Node {
4-
React.unstable_useMemoCache(1);
5+
useMemoCache(1);
56

67
return null;
78
}

packages/react-reconciler/src/__tests__/useMemoCache-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ describe('useMemoCache()', () => {
2727
Scheduler = require('scheduler');
2828
act = require('internal-test-utils').act;
2929
assertLog = require('internal-test-utils').assertLog;
30+
useMemoCache = require('react/compiler-runtime').c;
3031
useState = React.useState;
31-
useMemoCache = React.unstable_useMemoCache;
3232
MemoCacheSentinel = Symbol.for('react.memo_cache_sentinel');
3333

3434
class _ErrorBoundary extends React.Component {

packages/react/compiler-runtime.js

+10
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export {
3636
unstable_SuspenseList,
3737
unstable_getCacheForType,
3838
unstable_useCacheRefresh,
39-
unstable_useMemoCache,
4039
useId,
4140
useCallback,
4241
useContext,
@@ -57,4 +56,12 @@ export {
5756
useActionState,
5857
version,
5958
} from './src/ReactClient';
59+
6060
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
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export {
3434
unstable_getCacheForType,
3535
unstable_SuspenseList,
3636
unstable_useCacheRefresh,
37-
unstable_useMemoCache,
3837
useId,
3938
useCallback,
4039
useContext,

packages/react/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export {
5757
unstable_TracingMarker,
5858
unstable_getCacheForType,
5959
unstable_useCacheRefresh,
60-
unstable_useMemoCache,
6160
useId,
6261
useCallback,
6362
useContext,

packages/react/index.modern.fb.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export {
3636
unstable_TracingMarker,
3737
unstable_getCacheForType,
3838
unstable_useCacheRefresh,
39-
unstable_useMemoCache,
4039
useId,
4140
useCallback,
4241
useContext,
@@ -58,3 +57,10 @@ export {
5857
version,
5958
} from './src/ReactClient';
6059
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';
+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+
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
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"README.md",
1414
"index.js",
1515
"cjs/",
16+
"compiler-runtime.js",
1617
"jsx-runtime.js",
1718
"jsx-runtime.react-server.js",
1819
"jsx-dev-runtime.js",
@@ -34,6 +35,10 @@
3435
"react-server": "./jsx-dev-runtime.react-server.js",
3536
"default": "./jsx-dev-runtime.js"
3637
},
38+
"./compiler-runtime": {
39+
"react-server": "./compiler-runtime.js",
40+
"default": "./compiler-runtime.js"
41+
},
3742
"./src/*": "./src/*"
3843
},
3944
"repository": {

packages/react/src/ReactClient.js

-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import {
5555
useId,
5656
useCacheRefresh,
5757
use,
58-
useMemoCache,
5958
useOptimistic,
6059
useActionState,
6160
} from './ReactHooks';
@@ -117,7 +116,6 @@ export {
117116
getCacheForType as unstable_getCacheForType,
118117
useCacheRefresh as unstable_useCacheRefresh,
119118
use,
120-
useMemoCache as unstable_useMemoCache,
121119
// enableScopeAPI
122120
REACT_SCOPE_TYPE as unstable_Scope,
123121
// enableTransitionTracing

packages/shared/ReactFeatureFlags.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const enableSuspenseAvoidThisFallbackFizz = false;
102102

103103
export const enableCPUSuspense = __EXPERIMENTAL__;
104104

105-
// Enables unstable_useMemoCache hook, intended as a compilation target for
105+
// Enables useMemoCache hook, intended as a compilation target for
106106
// auto-memoization.
107107
export const enableUseMemoCacheHook = __EXPERIMENTAL__;
108108
// Test this at Meta before enabling.

packages/shared/forks/ReactFeatureFlags.test-renderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const disableTextareaChildren = false;
3636
export const enableSuspenseAvoidThisFallback = false;
3737
export const enableSuspenseAvoidThisFallbackFizz = false;
3838
export const enableCPUSuspense = false;
39-
export const enableUseMemoCacheHook = true;
39+
export const enableUseMemoCacheHook = __EXPERIMENTAL__;
4040
export const enableNoCloningMemoCache = false;
4141
export const enableUseEffectEventHook = false;
4242
export const favorSafetyOverHydrationPerf = true;

scripts/rollup/bundles.js

+11
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ const bundles = [
115115
externals: ['react', 'ReactNativeInternalFeatureFlags'],
116116
},
117117

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+
118129
/******* React JSX Runtime React Server *******/
119130
{
120131
bundleTypes: [NODE_DEV, NODE_PROD],

0 commit comments

Comments
 (0)