Skip to content

Commit dea13f1

Browse files
author
Brian Vaughn
committed
Addressed PR feedback and tweaked a few things:
* Removed "render scheduled" message; it was the only one outside of the <Mode> and just didn't feel worth the added noise. * Added SSR pass through (and tests) * Add promise resolution/rejection logging * Removed debug mode from "react-is" package * Export for the symbol if the feature flag is off
1 parent 916873e commit dea13f1

File tree

11 files changed

+337
-286
lines changed

11 files changed

+337
-286
lines changed

packages/react-devtools-shared/src/utils.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
ForwardRef,
1717
Fragment,
1818
Lazy,
19-
DebugTraceMode,
2019
Memo,
2120
Portal,
2221
Profiler,
@@ -433,8 +432,6 @@ export function getDisplayNameForReactElement(
433432
return 'Fragment';
434433
case Lazy:
435434
return 'Lazy';
436-
case DebugTraceMode:
437-
return 'DebugTraceMode';
438435
case Memo:
439436
return 'Memo';
440437
case Portal:

packages/react-dom/src/__tests__/ReactDOMServerIntegrationModes-test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,53 @@ describe('ReactDOMServerIntegration', () => {
3939
resetModules();
4040
});
4141

42+
// Test pragmas don't support itRenders abstraction
43+
if (require('shared/ReactFeatureFlags').enableDebugTracing) {
44+
describe('React.DebugTraceMode', () => {
45+
beforeEach(() => {
46+
spyOnDevAndProd(console, 'log');
47+
});
48+
49+
itRenders('with one child', async render => {
50+
const e = await render(
51+
<React.DebugTraceMode>
52+
<div>text1</div>
53+
</React.DebugTraceMode>,
54+
);
55+
const parent = e.parentNode;
56+
expect(parent.childNodes[0].tagName).toBe('DIV');
57+
});
58+
59+
itRenders('mode with several children', async render => {
60+
const Header = props => {
61+
return <p>header</p>;
62+
};
63+
const Footer = props => {
64+
return (
65+
<React.DebugTraceMode>
66+
<h2>footer</h2>
67+
<h3>about</h3>
68+
</React.DebugTraceMode>
69+
);
70+
};
71+
const e = await render(
72+
<React.DebugTraceMode>
73+
<div>text1</div>
74+
<span>text2</span>
75+
<Header />
76+
<Footer />
77+
</React.DebugTraceMode>,
78+
);
79+
const parent = e.parentNode;
80+
expect(parent.childNodes[0].tagName).toBe('DIV');
81+
expect(parent.childNodes[1].tagName).toBe('SPAN');
82+
expect(parent.childNodes[2].tagName).toBe('P');
83+
expect(parent.childNodes[3].tagName).toBe('H2');
84+
expect(parent.childNodes[4].tagName).toBe('H3');
85+
});
86+
});
87+
}
88+
4289
describe('React.StrictMode', () => {
4390
itRenders('a strict mode with one child', async render => {
4491
const e = await render(

packages/react-dom/src/server/ReactPartialRenderer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
} from 'shared/ReactFeatureFlags';
2929

3030
import {
31+
REACT_DEBUG_TRACE_MODE_TYPE,
3132
REACT_FORWARD_REF_TYPE,
3233
REACT_FRAGMENT_TYPE,
3334
REACT_STRICT_MODE_TYPE,
@@ -1002,6 +1003,7 @@ class ReactDOMServerRenderer {
10021003
}
10031004

10041005
switch (elementType) {
1006+
case REACT_DEBUG_TRACE_MODE_TYPE:
10051007
case REACT_STRICT_MODE_TYPE:
10061008
case REACT_PROFILER_TYPE:
10071009
case REACT_SUSPENSE_LIST_TYPE:

packages/react-is/src/ReactIs.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
REACT_FORWARD_REF_TYPE,
1616
REACT_FRAGMENT_TYPE,
1717
REACT_LAZY_TYPE,
18-
REACT_DEBUG_TRACE_MODE_TYPE,
1918
REACT_MEMO_TYPE,
2019
REACT_PORTAL_TYPE,
2120
REACT_PROFILER_TYPE,
@@ -66,7 +65,6 @@ export const Element = REACT_ELEMENT_TYPE;
6665
export const ForwardRef = REACT_FORWARD_REF_TYPE;
6766
export const Fragment = REACT_FRAGMENT_TYPE;
6867
export const Lazy = REACT_LAZY_TYPE;
69-
export const DebugTraceMode = REACT_DEBUG_TRACE_MODE_TYPE;
7068
export const Memo = REACT_MEMO_TYPE;
7169
export const Portal = REACT_PORTAL_TYPE;
7270
export const Profiler = REACT_PROFILER_TYPE;
@@ -127,9 +125,6 @@ export function isFragment(object: any) {
127125
export function isLazy(object: any) {
128126
return typeOf(object) === REACT_LAZY_TYPE;
129127
}
130-
export function isDebugTraceMode(object: any) {
131-
return typeOf(object) === REACT_DEBUG_TRACE_MODE_TYPE;
132-
}
133128
export function isMemo(object: any) {
134129
return typeOf(object) === REACT_MEMO_TYPE;
135130
}

packages/react-reconciler/src/DebugTrace.js

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,49 @@ export function logCommitStopped(): void {
6868
groupEnd();
6969
}
7070

71+
const PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
72+
// $FlowFixMe: Flow cannot handle polymorphic WeakMaps
73+
const wakeableIDs: WeakMap<Wakeable, number> = new PossiblyWeakMap();
74+
let wakeableID: number = 0;
75+
function getWakeableID(wakeable: Wakeable): number {
76+
if (!wakeableIDs.has(wakeable)) {
77+
wakeableIDs.set(wakeable, wakeableID++);
78+
}
79+
return ((wakeableIDs.get(wakeable): any): number);
80+
}
81+
7182
export function logComponentSuspended(
7283
componentName: string,
7384
wakeable: Wakeable,
7485
): void {
86+
const id = getWakeableID(wakeable);
87+
const display = (wakeable: any).displayName || wakeable;
7588
log(
7689
`%c⚛️%c ${componentName} suspended`,
7790
REACT_LOGO_STYLE,
7891
'color: #80366d; font-weight: bold;',
79-
wakeable,
92+
id,
93+
display,
94+
);
95+
wakeable.then(
96+
() => {
97+
log(
98+
`%c⚛️%c ${componentName} resolved`,
99+
REACT_LOGO_STYLE,
100+
'color: #80366d; font-weight: bold;',
101+
id,
102+
display,
103+
);
104+
},
105+
() => {
106+
log(
107+
`%c⚛️%c ${componentName} rejected`,
108+
REACT_LOGO_STYLE,
109+
'color: #80366d; font-weight: bold;',
110+
id,
111+
display,
112+
);
113+
},
80114
);
81115
}
82116

@@ -131,15 +165,6 @@ export function logForceUpdateScheduled(
131165
);
132166
}
133167

134-
export function logRenderScheduled(priorityLabel: string): void {
135-
log(
136-
`%c⚛️%c render scheduled%c (priority: ${priorityLabel})`,
137-
REACT_LOGO_STYLE,
138-
'color: #0265e3; font-weight: bold;',
139-
'',
140-
);
141-
}
142-
143168
export function logStateUpdateScheduled(
144169
componentName: string,
145170
priorityLabel: string,

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import {
3636
import getComponentName from 'shared/getComponentName';
3737
import invariant from 'shared/invariant';
3838
import ReactSharedInternals from 'shared/ReactSharedInternals';
39-
import {enableDebugTracing} from 'shared/ReactFeatureFlags';
4039
import {getPublicInstance} from './ReactFiberHostConfig';
4140
import {
4241
findCurrentUnmaskedContext,
@@ -65,7 +64,6 @@ import {
6564
warnIfUnmockedScheduler,
6665
IsThisRendererActing,
6766
act,
68-
priorityLevelToLabel,
6967
} from './ReactFiberWorkLoop.new';
7068
import {createUpdate, enqueueUpdate} from './ReactUpdateQueue.new';
7169
import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';
@@ -78,7 +76,6 @@ import {
7876
Sync,
7977
ContinuousHydration,
8078
computeInteractiveExpiration,
81-
inferPriorityFromExpirationTime,
8279
} from './ReactFiberExpirationTime.new';
8380
import {requestCurrentSuspenseConfig} from './ReactFiberSuspenseConfig';
8481
import {
@@ -87,7 +84,6 @@ import {
8784
setRefreshHandler,
8885
findHostInstancesForRefresh,
8986
} from './ReactFiberHotReloading.new';
90-
import {logRenderScheduled} from './DebugTrace';
9187

9288
export {createPortal} from './ReactPortal';
9389

@@ -246,17 +242,6 @@ export function updateContainer(
246242
suspenseConfig,
247243
);
248244

249-
if (__DEV__) {
250-
if (enableDebugTracing) {
251-
const priorityLevel = inferPriorityFromExpirationTime(
252-
currentTime,
253-
expirationTime,
254-
);
255-
const label = priorityLevelToLabel(priorityLevel);
256-
logRenderScheduled(label);
257-
}
258-
}
259-
260245
const context = getContextForSubtree(parentComponent);
261246
if (container.context === null) {
262247
container.context = context;

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import {
3636
import getComponentName from 'shared/getComponentName';
3737
import invariant from 'shared/invariant';
3838
import ReactSharedInternals from 'shared/ReactSharedInternals';
39-
import {enableDebugTracing} from 'shared/ReactFeatureFlags';
4039
import {getPublicInstance} from './ReactFiberHostConfig';
4140
import {
4241
findCurrentUnmaskedContext,
@@ -65,7 +64,6 @@ import {
6564
warnIfUnmockedScheduler,
6665
IsThisRendererActing,
6766
act,
68-
priorityLevelToLabel,
6967
} from './ReactFiberWorkLoop.old';
7068
import {createUpdate, enqueueUpdate} from './ReactUpdateQueue.old';
7169
import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';
@@ -78,7 +76,6 @@ import {
7876
Sync,
7977
ContinuousHydration,
8078
computeInteractiveExpiration,
81-
inferPriorityFromExpirationTime,
8279
} from './ReactFiberExpirationTime.old';
8380
import {requestCurrentSuspenseConfig} from './ReactFiberSuspenseConfig';
8481
import {
@@ -87,7 +84,6 @@ import {
8784
setRefreshHandler,
8885
findHostInstancesForRefresh,
8986
} from './ReactFiberHotReloading.old';
90-
import {logRenderScheduled} from './DebugTrace';
9187

9288
export {createPortal} from './ReactPortal';
9389

@@ -246,17 +242,6 @@ export function updateContainer(
246242
suspenseConfig,
247243
);
248244

249-
if (__DEV__) {
250-
if (enableDebugTracing) {
251-
const priorityLevel = inferPriorityFromExpirationTime(
252-
currentTime,
253-
expirationTime,
254-
);
255-
const label = priorityLevelToLabel(priorityLevel);
256-
logRenderScheduled(label);
257-
}
258-
}
259-
260245
const context = getContextForSubtree(parentComponent);
261246
if (container.context === null) {
262247
container.context = context;

packages/react-reconciler/src/ReactTypeOfMode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export type TypeOfMode = number;
1111

1212
export const NoMode = 0b00000;
1313
export const StrictMode = 0b00001;
14-
export const DebugTraceMode = 0b10000;
1514
// TODO: Remove BlockingMode and ConcurrentMode by reading from the root
1615
// tag instead
1716
export const BlockingMode = 0b00010;
1817
export const ConcurrentMode = 0b00100;
1918
export const ProfileMode = 0b01000;
19+
export const DebugTraceMode = 0b10000;

0 commit comments

Comments
 (0)