Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more feature flag checks #24037

Merged
merged 1 commit into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator Author

@sebmarkbage sebmarkbage Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trick is to place these at the bottom so if the condition is false it's the same as default which means that the case is unnecessary which Closure is smart enough to understand but not Rollup.

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