Skip to content

Commit a496498

Browse files
Noah Lemenrickhanlonii
andauthored
Make enableOwnerStacks dynamic (#31661)
following up on #31287, fixing tests --------- Co-authored-by: Rick Hanlon <[email protected]>
1 parent 92b62f5 commit a496498

8 files changed

+92
-37
lines changed

packages/react/index.fb.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* @flow
88
*/
99

10+
import {enableOwnerStacks} from 'shared/ReactFeatureFlags';
11+
import {captureOwnerStack as captureOwnerStackImpl} from './src/ReactClient';
1012
export {
1113
__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
1214
__COMPILER_RUNTIME,
@@ -68,3 +70,11 @@ export {useMemoCache as unstable_useMemoCache} from './src/ReactHooks';
6870
// export to match the name of the OSS function typically exported from
6971
// react/compiler-runtime
7072
export {useMemoCache as c} from './src/ReactHooks';
73+
74+
// Only export captureOwnerStack in development.
75+
let captureOwnerStack: ?() => null | string;
76+
if (__DEV__ && enableOwnerStacks) {
77+
captureOwnerStack = captureOwnerStackImpl;
78+
}
79+
80+
export {captureOwnerStack};

packages/react/src/ReactServer.fb.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
export {default as __SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE} from './ReactSharedInternalsServer';
1111

1212
import {forEach, map, count, toArray, only} from './ReactChildren';
13+
import {enableOwnerStacks} from 'shared/ReactFeatureFlags';
14+
import {captureOwnerStack as captureOwnerStackImpl} from './ReactOwnerStack';
1315
import {
1416
REACT_FRAGMENT_TYPE,
1517
REACT_PROFILER_TYPE,
@@ -37,6 +39,12 @@ const Children = {
3739
only,
3840
};
3941

42+
// Only export captureOwnerStack if the flag is on, to support feature detection.
43+
let captureOwnerStack: ?() => null | string;
44+
if (__DEV__ && enableOwnerStacks) {
45+
captureOwnerStack = captureOwnerStackImpl;
46+
}
47+
4048
export {
4149
Children,
4250
REACT_FRAGMENT_TYPE as Fragment,
@@ -57,4 +65,5 @@ export {
5765
useDebugValue,
5866
useMemo,
5967
version,
68+
captureOwnerStack, // DEV-only
6069
};

packages/react/src/__tests__/ReactStrictMode-test.js

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,40 +1028,67 @@ describe('context legacy', () => {
10281028
root.render(<Root />);
10291029
});
10301030

1031-
assertConsoleErrorDev([
1032-
'LegacyContextProvider uses the legacy childContextTypes API ' +
1033-
'which will soon be removed. Use React.createContext() instead. ' +
1034-
'(https://react.dev/link/legacy-context)' +
1035-
'\n in LegacyContextProvider (at **)' +
1036-
'\n in div (at **)' +
1037-
'\n in Root (at **)',
1038-
'LegacyContextConsumer uses the legacy contextTypes API which ' +
1039-
'will soon be removed. Use React.createContext() with static ' +
1040-
'contextType instead. (https://react.dev/link/legacy-context)' +
1041-
'\n in LegacyContextConsumer (at **)' +
1042-
'\n in div (at **)' +
1043-
'\n in LegacyContextProvider (at **)' +
1044-
'\n in div (at **)' +
1045-
'\n in Root (at **)',
1046-
'FunctionalLegacyContextConsumer uses the legacy contextTypes ' +
1047-
'API which will be removed soon. Use React.createContext() ' +
1048-
'with React.useContext() instead. (https://react.dev/link/legacy-context)' +
1049-
'\n in FunctionalLegacyContextConsumer (at **)' +
1050-
'\n in div (at **)' +
1051-
'\n in LegacyContextProvider (at **)' +
1052-
'\n in div (at **)' +
1053-
'\n in Root (at **)',
1054-
'Legacy context API has been detected within a strict-mode tree.' +
1055-
'\n\nThe old API will be supported in all 16.x releases, but applications ' +
1056-
'using it should migrate to the new version.' +
1057-
'\n\nPlease update the following components: ' +
1058-
'FunctionalLegacyContextConsumer, LegacyContextConsumer, LegacyContextProvider' +
1059-
'\n\nLearn more about this warning here: ' +
1060-
'https://react.dev/link/legacy-context' +
1061-
'\n in LegacyContextProvider (at **)' +
1062-
'\n in div (at **)' +
1063-
'\n in Root (at **)',
1064-
]);
1031+
if (gate(flags => flags.enableOwnerStacks)) {
1032+
assertConsoleErrorDev([
1033+
'LegacyContextProvider uses the legacy childContextTypes API ' +
1034+
'which will soon be removed. Use React.createContext() instead. ' +
1035+
'(https://react.dev/link/legacy-context)' +
1036+
'\n in Root (at **)',
1037+
'LegacyContextConsumer uses the legacy contextTypes API which ' +
1038+
'will soon be removed. Use React.createContext() with static ' +
1039+
'contextType instead. (https://react.dev/link/legacy-context)' +
1040+
'\n in LegacyContextProvider (at **)' +
1041+
'\n in Root (at **)',
1042+
'FunctionalLegacyContextConsumer uses the legacy contextTypes ' +
1043+
'API which will be removed soon. Use React.createContext() ' +
1044+
'with React.useContext() instead. (https://react.dev/link/legacy-context)' +
1045+
'\n in LegacyContextProvider (at **)' +
1046+
'\n in Root (at **)',
1047+
'Legacy context API has been detected within a strict-mode tree.' +
1048+
'\n\nThe old API will be supported in all 16.x releases, but applications ' +
1049+
'using it should migrate to the new version.' +
1050+
'\n\nPlease update the following components: ' +
1051+
'FunctionalLegacyContextConsumer, LegacyContextConsumer, LegacyContextProvider' +
1052+
'\n\nLearn more about this warning here: ' +
1053+
'https://react.dev/link/legacy-context' +
1054+
'\n in Root (at **)',
1055+
]);
1056+
} else {
1057+
assertConsoleErrorDev([
1058+
'LegacyContextProvider uses the legacy childContextTypes API ' +
1059+
'which will soon be removed. Use React.createContext() instead. ' +
1060+
'(https://react.dev/link/legacy-context)' +
1061+
'\n in LegacyContextProvider (at **)' +
1062+
'\n in div (at **)' +
1063+
'\n in Root (at **)',
1064+
'LegacyContextConsumer uses the legacy contextTypes API which ' +
1065+
'will soon be removed. Use React.createContext() with static ' +
1066+
'contextType instead. (https://react.dev/link/legacy-context)' +
1067+
'\n in LegacyContextConsumer (at **)' +
1068+
'\n in div (at **)' +
1069+
'\n in LegacyContextProvider (at **)' +
1070+
'\n in div (at **)' +
1071+
'\n in Root (at **)',
1072+
'FunctionalLegacyContextConsumer uses the legacy contextTypes ' +
1073+
'API which will be removed soon. Use React.createContext() ' +
1074+
'with React.useContext() instead. (https://react.dev/link/legacy-context)' +
1075+
'\n in FunctionalLegacyContextConsumer (at **)' +
1076+
'\n in div (at **)' +
1077+
'\n in LegacyContextProvider (at **)' +
1078+
'\n in div (at **)' +
1079+
'\n in Root (at **)',
1080+
'Legacy context API has been detected within a strict-mode tree.' +
1081+
'\n\nThe old API will be supported in all 16.x releases, but applications ' +
1082+
'using it should migrate to the new version.' +
1083+
'\n\nPlease update the following components: ' +
1084+
'FunctionalLegacyContextConsumer, LegacyContextConsumer, LegacyContextProvider' +
1085+
'\n\nLearn more about this warning here: ' +
1086+
'https://react.dev/link/legacy-context' +
1087+
'\n in LegacyContextProvider (at **)' +
1088+
'\n in div (at **)' +
1089+
'\n in Root (at **)',
1090+
]);
1091+
}
10651092

10661093
// Dedupe
10671094
await act(() => {

packages/react/src/__tests__/createReactClassIntegration-test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,14 @@ describe('create-react-class-integration', () => {
338338
root.render(<Outer />);
339339
});
340340
assertConsoleErrorDev([
341-
'Component uses the legacy childContextTypes API which will soon be removed. Use React.createContext() instead.',
341+
gate(flags =>
342+
flags.enableOwnerStacks
343+
? [
344+
'Component uses the legacy childContextTypes API which will soon be removed. Use React.createContext() instead.',
345+
{withoutStack: true},
346+
]
347+
: 'Component uses the legacy childContextTypes API which will soon be removed. Use React.createContext() instead.',
348+
),
342349
'Component uses the legacy contextTypes API which will soon be removed. Use React.createContext() with static contextType instead.',
343350
]);
344351
expect(container.firstChild.className).toBe('foo');

packages/shared/forks/ReactFeatureFlags.native-fb-dynamic.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ export const passChildrenWhenCloningPersistedNodes = __VARIANT__;
2626
export const enableFabricCompleteRootInCommitPhase = __VARIANT__;
2727
export const enableSiblingPrerendering = __VARIANT__;
2828
export const enableUseResourceEffectHook = __VARIANT__;
29+
export const enableOwnerStacks = __VARIANT__;

packages/shared/forks/ReactFeatureFlags.native-fb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const {
2828
enableUseResourceEffectHook,
2929
passChildrenWhenCloningPersistedNodes,
3030
enableSiblingPrerendering,
31+
enableOwnerStacks,
3132
} = dynamicFlags;
3233

3334
// The rest of the flags are static for better dead code elimination.
@@ -67,7 +68,6 @@ export const enableLegacyCache = false;
6768
export const enableLegacyFBSupport = false;
6869
export const enableLegacyHidden = false;
6970
export const enableNoCloningMemoCache = false;
70-
export const enableOwnerStacks = false;
7171
export const enablePostpone = false;
7272
export const enableProfilerCommitHooks = __PROFILE__;
7373
export const enableProfilerNestedUpdatePhase = __PROFILE__;

packages/shared/forks/ReactFeatureFlags.www-dynamic.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const enableRetryLaneExpiration = __VARIANT__;
2727
export const enableTransitionTracing = __VARIANT__;
2828
export const favorSafetyOverHydrationPerf = __VARIANT__;
2929
export const renameElementSymbol = __VARIANT__;
30+
export const enableOwnerStacks = __VARIANT__;
3031
export const retryLaneExpirationMs = 5000;
3132
export const syncLaneExpirationMs = 250;
3233
export const transitionLaneExpirationMs = 5000;

packages/shared/forks/ReactFeatureFlags.www.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const {
3737
retryLaneExpirationMs,
3838
syncLaneExpirationMs,
3939
transitionLaneExpirationMs,
40+
enableOwnerStacks,
4041
} = dynamicFeatureFlags;
4142

4243
// On WWW, __EXPERIMENTAL__ is used for a new modern build.
@@ -121,7 +122,6 @@ export const useModernStrictMode = true;
121122

122123
export const disableLegacyMode = true;
123124

124-
export const enableOwnerStacks = false;
125125
export const enableShallowPropDiffing = false;
126126

127127
// Flow magic to verify the exports of this file match the original version.

0 commit comments

Comments
 (0)