Skip to content

Commit

Permalink
Add more feature flag checks (#24037)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage authored Mar 8, 2022
1 parent e09518e commit 57799b9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
12 changes: 8 additions & 4 deletions packages/react-reconciler/src/ReactFiber.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
enableSyncDefaultUpdates,
allowConcurrentByDefault,
enableTransitionTracing,
enableDebugTracing,
} from 'shared/ReactFeatureFlags';
import {
supportsPersistence,
Expand Down Expand Up @@ -492,10 +493,6 @@ export function createFiberFromTypeAndProps(
getTag: switch (type) {
case REACT_FRAGMENT_TYPE:
return createFiberFromFragment(pendingProps.children, mode, lanes, key);
case REACT_DEBUG_TRACING_MODE_TYPE:
fiberTag = Mode;
mode |= DebugTracingMode;
break;
case REACT_STRICT_MODE_TYPE:
fiberTag = Mode;
mode |= StrictLegacyMode;
Expand Down Expand Up @@ -529,6 +526,13 @@ export function createFiberFromTypeAndProps(
return createFiberFromTracingMarker(pendingProps, mode, lanes, key);
}
// eslint-disable-next-line no-fallthrough
case REACT_DEBUG_TRACING_MODE_TYPE:
if (enableDebugTracing) {
fiberTag = Mode;
mode |= DebugTracingMode;
break;
}
// eslint-disable-next-line no-fallthrough
default: {
if (typeof type === 'object' && type !== null) {
switch (type.$$typeof) {
Expand Down
12 changes: 8 additions & 4 deletions packages/react-reconciler/src/ReactFiber.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
enableSyncDefaultUpdates,
allowConcurrentByDefault,
enableTransitionTracing,
enableDebugTracing,
} from 'shared/ReactFeatureFlags';
import {
supportsPersistence,
Expand Down Expand Up @@ -492,10 +493,6 @@ export function createFiberFromTypeAndProps(
getTag: switch (type) {
case REACT_FRAGMENT_TYPE:
return createFiberFromFragment(pendingProps.children, mode, lanes, key);
case REACT_DEBUG_TRACING_MODE_TYPE:
fiberTag = Mode;
mode |= DebugTracingMode;
break;
case REACT_STRICT_MODE_TYPE:
fiberTag = Mode;
mode |= StrictLegacyMode;
Expand Down Expand Up @@ -529,6 +526,13 @@ export function createFiberFromTypeAndProps(
return createFiberFromTracingMarker(pendingProps, mode, lanes, key);
}
// eslint-disable-next-line no-fallthrough
case REACT_DEBUG_TRACING_MODE_TYPE:
if (enableDebugTracing) {
fiberTag = Mode;
mode |= DebugTracingMode;
break;
}
// eslint-disable-next-line no-fallthrough
default: {
if (typeof type === 'object' && type !== null) {
switch (type.$$typeof) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('DebugTracing', () => {
});
});

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

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

// @gate build === 'development'
// @gate experimental || www
// @gate experimental && build === 'development' && enableDebugTracing
it('should not log anything outside of a unstable_DebugTracingMode subtree', () => {
function ExampleThatCascades() {
const [didMount, setDidMount] = React.useState(false);
Expand Down
11 changes: 9 additions & 2 deletions packages/shared/getComponentNameFromType.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
REACT_TRACING_MARKER_TYPE,
} from 'shared/ReactSymbols';

import {enableTransitionTracing, enableCache} from './ReactFeatureFlags';

// Keep in sync with react-reconciler/getComponentNameFromFiber
function getWrappedName(
outerType: mixed,
Expand Down Expand Up @@ -79,9 +81,14 @@ export default function getComponentNameFromType(type: mixed): string | null {
case REACT_SUSPENSE_LIST_TYPE:
return 'SuspenseList';
case REACT_CACHE_TYPE:
return 'Cache';
if (enableCache) {
return 'Cache';
}
// eslint-disable-next-line no-fallthrough
case REACT_TRACING_MARKER_TYPE:
return 'TracingMarker';
if (enableTransitionTracing) {
return 'TracingMarker';
}
}
if (typeof type === 'object') {
switch (type.$$typeof) {
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/isValidElementType.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
enableScopeAPI,
enableCache,
enableTransitionTracing,
enableDebugTracing,
} from './ReactFeatureFlags';

const REACT_MODULE_REFERENCE: Symbol = Symbol.for('react.module.reference');
Expand All @@ -42,7 +43,7 @@ export default function isValidElementType(type: mixed) {
if (
type === REACT_FRAGMENT_TYPE ||
type === REACT_PROFILER_TYPE ||
type === REACT_DEBUG_TRACING_MODE_TYPE ||
(enableDebugTracing && type === REACT_DEBUG_TRACING_MODE_TYPE) ||
type === REACT_STRICT_MODE_TYPE ||
type === REACT_SUSPENSE_TYPE ||
type === REACT_SUSPENSE_LIST_TYPE ||
Expand Down

0 comments on commit 57799b9

Please sign in to comment.