Skip to content

Commit 9762527

Browse files
author
Brian Vaughn
authored
Debug tracing tests for CPU bound suspense (#19943)
1 parent 43363e2 commit 9762527

File tree

2 files changed

+121
-13
lines changed

2 files changed

+121
-13
lines changed

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

+120-12
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,45 @@ describe('DebugTracing', () => {
9696
expect(logs).toEqual(['log: ⚛️ Example resolved']);
9797
});
9898

99+
// @gate experimental && build === 'development' && enableDebugTracing
100+
it('should log sync render with CPU suspense', () => {
101+
function Example() {
102+
console.log('<Example/>');
103+
return null;
104+
}
105+
106+
function Wrapper({children}) {
107+
console.log('<Wrapper/>');
108+
return children;
109+
}
110+
111+
ReactTestRenderer.create(
112+
<React.unstable_DebugTracingMode>
113+
<Wrapper>
114+
<React.Suspense fallback={null} unstable_expectedLoadTime={1}>
115+
<Example />
116+
</React.Suspense>
117+
</Wrapper>
118+
</React.unstable_DebugTracingMode>,
119+
);
120+
121+
expect(logs).toEqual([
122+
'group: ⚛️ render (0b0000000000000000000000000000001)',
123+
'log: <Wrapper/>',
124+
'groupEnd: ⚛️ render (0b0000000000000000000000000000001)',
125+
]);
126+
127+
logs.splice(0);
128+
129+
expect(Scheduler).toFlushUntilNextPaint([]);
130+
131+
expect(logs).toEqual([
132+
'group: ⚛️ render (0b0000010000000000000000000000000)',
133+
'log: <Example/>',
134+
'groupEnd: ⚛️ render (0b0000010000000000000000000000000)',
135+
]);
136+
});
137+
99138
// @gate experimental && build === 'development' && enableDebugTracing
100139
it('should log concurrent render with suspense', async () => {
101140
const fakeSuspensePromise = Promise.resolve(true);
@@ -130,6 +169,52 @@ describe('DebugTracing', () => {
130169
expect(logs).toEqual(['log: ⚛️ Example resolved']);
131170
});
132171

172+
// @gate experimental && build === 'development' && enableDebugTracing
173+
it('should log concurrent render with CPU suspense', () => {
174+
function Example() {
175+
console.log('<Example/>');
176+
return null;
177+
}
178+
179+
function Wrapper({children}) {
180+
console.log('<Wrapper/>');
181+
return children;
182+
}
183+
184+
ReactTestRenderer.create(
185+
<React.unstable_DebugTracingMode>
186+
<Wrapper>
187+
<React.Suspense fallback={null} unstable_expectedLoadTime={1}>
188+
<Example />
189+
</React.Suspense>
190+
</Wrapper>
191+
</React.unstable_DebugTracingMode>,
192+
{unstable_isConcurrent: true},
193+
);
194+
195+
expect(logs).toEqual([]);
196+
197+
logs.splice(0);
198+
199+
expect(Scheduler).toFlushUntilNextPaint([]);
200+
201+
expect(logs).toEqual([
202+
'group: ⚛️ render (0b0000000000000000000001000000000)',
203+
'log: <Wrapper/>',
204+
'groupEnd: ⚛️ render (0b0000000000000000000001000000000)',
205+
]);
206+
207+
logs.splice(0);
208+
209+
expect(Scheduler).toFlushUntilNextPaint([]);
210+
211+
expect(logs).toEqual([
212+
'group: ⚛️ render (0b0000010000000000000000000000000)',
213+
'log: <Example/>',
214+
'groupEnd: ⚛️ render (0b0000010000000000000000000000000)',
215+
]);
216+
});
217+
133218
// @gate experimental && build === 'development' && enableDebugTracing
134219
it('should log cascading class component updates', () => {
135220
class Example extends React.Component {
@@ -191,12 +276,23 @@ describe('DebugTracing', () => {
191276
expect(Scheduler).toFlushUntilNextPaint([]);
192277
}).toErrorDev('Cannot update during an existing state transition');
193278

194-
expect(logs).toEqual([
195-
'group: ⚛️ render (0b0000000000000000000001000000000)',
196-
'log: ⚛️ Example updated state (0b0000000000000000000010000000000)',
197-
'log: ⚛️ Example updated state (0b0000000000000000000010000000000)',
198-
'groupEnd: ⚛️ render (0b0000000000000000000001000000000)',
199-
]);
279+
gate(flags => {
280+
if (flags.new) {
281+
expect(logs).toEqual([
282+
'group: ⚛️ render (0b0000000000000000000001000000000)',
283+
'log: ⚛️ Example updated state (0b0000000000000000000001000000000)',
284+
'log: ⚛️ Example updated state (0b0000000000000000000001000000000)',
285+
'groupEnd: ⚛️ render (0b0000000000000000000001000000000)',
286+
]);
287+
} else {
288+
expect(logs).toEqual([
289+
'group: ⚛️ render (0b0000000000000000000001000000000)',
290+
'log: ⚛️ Example updated state (0b0000000000000000000010000000000)',
291+
'log: ⚛️ Example updated state (0b0000000000000000000010000000000)',
292+
'groupEnd: ⚛️ render (0b0000000000000000000001000000000)',
293+
]);
294+
}
295+
});
200296
});
201297

202298
// @gate experimental && build === 'development' && enableDebugTracing
@@ -274,12 +370,24 @@ describe('DebugTracing', () => {
274370
{unstable_isConcurrent: true},
275371
);
276372
});
277-
expect(logs).toEqual([
278-
'group: ⚛️ render (0b0000000000000000000001000000000)',
279-
'log: ⚛️ Example updated state (0b0000000000000000000010000000000)',
280-
'log: ⚛️ Example updated state (0b0000000000000000000010000000000)', // debugRenderPhaseSideEffectsForStrictMode
281-
'groupEnd: ⚛️ render (0b0000000000000000000001000000000)',
282-
]);
373+
374+
gate(flags => {
375+
if (flags.new) {
376+
expect(logs).toEqual([
377+
'group: ⚛️ render (0b0000000000000000000001000000000)',
378+
'log: ⚛️ Example updated state (0b0000000000000000000001000000000)',
379+
'log: ⚛️ Example updated state (0b0000000000000000000001000000000)', // debugRenderPhaseSideEffectsForStrictMode
380+
'groupEnd: ⚛️ render (0b0000000000000000000001000000000)',
381+
]);
382+
} else {
383+
expect(logs).toEqual([
384+
'group: ⚛️ render (0b0000000000000000000001000000000)',
385+
'log: ⚛️ Example updated state (0b0000000000000000000010000000000)',
386+
'log: ⚛️ Example updated state (0b0000000000000000000010000000000)', // debugRenderPhaseSideEffectsForStrictMode
387+
'groupEnd: ⚛️ render (0b0000000000000000000001000000000)',
388+
]);
389+
}
390+
});
283391
});
284392

285393
// @gate experimental && build === 'development' && enableDebugTracing

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const enableEagerRootListeners = !__VARIANT__;
2525
// It logs information to the console about React scheduling, rendering, and commit phases.
2626
//
2727
// NOTE: This feature will only work in DEV mode; all callsights are wrapped with __DEV__.
28-
export const enableDebugTracing = false;
28+
export const enableDebugTracing = __EXPERIMENTAL__;
2929

3030
// This only has an effect in the new reconciler. But also, the new reconciler
3131
// is only enabled when __VARIANT__ is true. So this is set to the opposite of

0 commit comments

Comments
 (0)