Skip to content

Commit 57799b9

Browse files
authored
Add more feature flag checks (#24037)
1 parent e09518e commit 57799b9

File tree

5 files changed

+30
-16
lines changed

5 files changed

+30
-16
lines changed

packages/react-reconciler/src/ReactFiber.new.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
enableSyncDefaultUpdates,
2727
allowConcurrentByDefault,
2828
enableTransitionTracing,
29+
enableDebugTracing,
2930
} from 'shared/ReactFeatureFlags';
3031
import {
3132
supportsPersistence,
@@ -492,10 +493,6 @@ export function createFiberFromTypeAndProps(
492493
getTag: switch (type) {
493494
case REACT_FRAGMENT_TYPE:
494495
return createFiberFromFragment(pendingProps.children, mode, lanes, key);
495-
case REACT_DEBUG_TRACING_MODE_TYPE:
496-
fiberTag = Mode;
497-
mode |= DebugTracingMode;
498-
break;
499496
case REACT_STRICT_MODE_TYPE:
500497
fiberTag = Mode;
501498
mode |= StrictLegacyMode;
@@ -529,6 +526,13 @@ export function createFiberFromTypeAndProps(
529526
return createFiberFromTracingMarker(pendingProps, mode, lanes, key);
530527
}
531528
// eslint-disable-next-line no-fallthrough
529+
case REACT_DEBUG_TRACING_MODE_TYPE:
530+
if (enableDebugTracing) {
531+
fiberTag = Mode;
532+
mode |= DebugTracingMode;
533+
break;
534+
}
535+
// eslint-disable-next-line no-fallthrough
532536
default: {
533537
if (typeof type === 'object' && type !== null) {
534538
switch (type.$$typeof) {

packages/react-reconciler/src/ReactFiber.old.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
enableSyncDefaultUpdates,
2727
allowConcurrentByDefault,
2828
enableTransitionTracing,
29+
enableDebugTracing,
2930
} from 'shared/ReactFeatureFlags';
3031
import {
3132
supportsPersistence,
@@ -492,10 +493,6 @@ export function createFiberFromTypeAndProps(
492493
getTag: switch (type) {
493494
case REACT_FRAGMENT_TYPE:
494495
return createFiberFromFragment(pendingProps.children, mode, lanes, key);
495-
case REACT_DEBUG_TRACING_MODE_TYPE:
496-
fiberTag = Mode;
497-
mode |= DebugTracingMode;
498-
break;
499496
case REACT_STRICT_MODE_TYPE:
500497
fiberTag = Mode;
501498
mode |= StrictLegacyMode;
@@ -529,6 +526,13 @@ export function createFiberFromTypeAndProps(
529526
return createFiberFromTracingMarker(pendingProps, mode, lanes, key);
530527
}
531528
// eslint-disable-next-line no-fallthrough
529+
case REACT_DEBUG_TRACING_MODE_TYPE:
530+
if (enableDebugTracing) {
531+
fiberTag = Mode;
532+
mode |= DebugTracingMode;
533+
break;
534+
}
535+
// eslint-disable-next-line no-fallthrough
532536
default: {
533537
if (typeof type === 'object' && type !== null) {
534538
switch (type.$$typeof) {

packages/react-reconciler/src/__tests__/DebugTracing-test.internal.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('DebugTracing', () => {
4545
});
4646
});
4747

48-
// @gate experimental || www
48+
// @gate enableDebugTracing
4949
it('should not log anything for sync render without suspends or state updates', () => {
5050
ReactTestRenderer.create(
5151
<React.unstable_DebugTracingMode>
@@ -56,8 +56,7 @@ describe('DebugTracing', () => {
5656
expect(logs).toEqual([]);
5757
});
5858

59-
// @gate build === 'development'
60-
// @gate experimental || www
59+
// @gate experimental && build === 'development' && enableDebugTracing
6160
it('should not log anything for concurrent render without suspends or state updates', () => {
6261
ReactTestRenderer.act(() =>
6362
ReactTestRenderer.create(
@@ -376,8 +375,7 @@ describe('DebugTracing', () => {
376375
]);
377376
});
378377

379-
// @gate build === 'development'
380-
// @gate experimental || www
378+
// @gate experimental && build === 'development' && enableDebugTracing
381379
it('should not log anything outside of a unstable_DebugTracingMode subtree', () => {
382380
function ExampleThatCascades() {
383381
const [didMount, setDidMount] = React.useState(false);

packages/shared/getComponentNameFromType.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {
2626
REACT_TRACING_MARKER_TYPE,
2727
} from 'shared/ReactSymbols';
2828

29+
import {enableTransitionTracing, enableCache} from './ReactFeatureFlags';
30+
2931
// Keep in sync with react-reconciler/getComponentNameFromFiber
3032
function getWrappedName(
3133
outerType: mixed,
@@ -79,9 +81,14 @@ export default function getComponentNameFromType(type: mixed): string | null {
7981
case REACT_SUSPENSE_LIST_TYPE:
8082
return 'SuspenseList';
8183
case REACT_CACHE_TYPE:
82-
return 'Cache';
84+
if (enableCache) {
85+
return 'Cache';
86+
}
87+
// eslint-disable-next-line no-fallthrough
8388
case REACT_TRACING_MARKER_TYPE:
84-
return 'TracingMarker';
89+
if (enableTransitionTracing) {
90+
return 'TracingMarker';
91+
}
8592
}
8693
if (typeof type === 'object') {
8794
switch (type.$$typeof) {

packages/shared/isValidElementType.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
enableScopeAPI,
3030
enableCache,
3131
enableTransitionTracing,
32+
enableDebugTracing,
3233
} from './ReactFeatureFlags';
3334

3435
const REACT_MODULE_REFERENCE: Symbol = Symbol.for('react.module.reference');
@@ -42,7 +43,7 @@ export default function isValidElementType(type: mixed) {
4243
if (
4344
type === REACT_FRAGMENT_TYPE ||
4445
type === REACT_PROFILER_TYPE ||
45-
type === REACT_DEBUG_TRACING_MODE_TYPE ||
46+
(enableDebugTracing && type === REACT_DEBUG_TRACING_MODE_TYPE) ||
4647
type === REACT_STRICT_MODE_TYPE ||
4748
type === REACT_SUSPENSE_TYPE ||
4849
type === REACT_SUSPENSE_LIST_TYPE ||

0 commit comments

Comments
 (0)