Skip to content

Commit d2037a0

Browse files
committed
Passing React 17
1 parent b08fe8f commit d2037a0

File tree

2 files changed

+116
-45
lines changed

2 files changed

+116
-45
lines changed

packages/react-devtools-shared/src/__tests__/profilingCache-test.js

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -724,34 +724,69 @@ describe('ProfilingCache', () => {
724724
const rootID = store.roots[0];
725725
const commitData = store.profilerStore.getDataForRoot(rootID).commitData;
726726
expect(commitData).toHaveLength(2);
727-
expect(commitData[0].fiberActualDurations).toMatchInlineSnapshot(`
728-
Map {
729-
1 => 15,
730-
2 => 15,
731-
3 => 5,
732-
4 => 2,
733-
}
734-
`);
735-
expect(commitData[0].fiberSelfDurations).toMatchInlineSnapshot(`
736-
Map {
737-
1 => 0,
738-
2 => 10,
739-
3 => 3,
740-
4 => 2,
741-
}
742-
`);
743-
expect(commitData[1].fiberActualDurations).toMatchInlineSnapshot(`
744-
Map {
745-
5 => 3,
746-
3 => 3,
747-
}
748-
`);
749-
expect(commitData[1].fiberSelfDurations).toMatchInlineSnapshot(`
750-
Map {
751-
5 => 3,
752-
3 => 0,
753-
}
754-
`);
727+
728+
const isLegacySuspense = React.version.startsWith('17');
729+
if (isLegacySuspense) {
730+
expect(commitData[0].fiberActualDurations).toMatchInlineSnapshot(`
731+
Map {
732+
1 => 15,
733+
2 => 15,
734+
3 => 5,
735+
4 => 3,
736+
5 => 2,
737+
}
738+
`);
739+
expect(commitData[0].fiberSelfDurations).toMatchInlineSnapshot(`
740+
Map {
741+
1 => 0,
742+
2 => 10,
743+
3 => 3,
744+
4 => 3,
745+
5 => 2,
746+
}
747+
`);
748+
expect(commitData[1].fiberActualDurations).toMatchInlineSnapshot(`
749+
Map {
750+
6 => 3,
751+
3 => 3,
752+
}
753+
`);
754+
expect(commitData[1].fiberSelfDurations).toMatchInlineSnapshot(`
755+
Map {
756+
6 => 3,
757+
3 => 0,
758+
}
759+
`);
760+
} else {
761+
expect(commitData[0].fiberActualDurations).toMatchInlineSnapshot(`
762+
Map {
763+
1 => 15,
764+
2 => 15,
765+
3 => 5,
766+
4 => 2,
767+
}
768+
`);
769+
expect(commitData[0].fiberSelfDurations).toMatchInlineSnapshot(`
770+
Map {
771+
1 => 0,
772+
2 => 10,
773+
3 => 3,
774+
4 => 2,
775+
}
776+
`);
777+
expect(commitData[1].fiberActualDurations).toMatchInlineSnapshot(`
778+
Map {
779+
5 => 3,
780+
3 => 3,
781+
}
782+
`);
783+
expect(commitData[1].fiberSelfDurations).toMatchInlineSnapshot(`
784+
Map {
785+
5 => 3,
786+
3 => 0,
787+
}
788+
`);
789+
}
755790
});
756791

757792
// @reactVersion >= 16.9

packages/react-devtools-shared/src/__tests__/profilingCommitTreeBuilder-test.js

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import {
1515
} from './utils';
1616

1717
describe('commit tree', () => {
18-
let React;
18+
let React = require('react');
1919
let Scheduler;
2020
let store: Store;
2121
let utils;
22+
const isLegacySuspense =
23+
React.version.startsWith('16') || React.version.startsWith('17');
2224

2325
beforeEach(() => {
2426
utils = require('./utils');
@@ -184,13 +186,24 @@ describe('commit tree', () => {
184186
utils.act(() => store.profilerStore.startProfiling());
185187
utils.act(() => legacyRender(<App renderChildren={true} />));
186188
await Promise.resolve();
187-
expect(store).toMatchInlineSnapshot(`
188-
[root]
189-
▾ <App>
190-
<Suspense>
191-
[suspense-root] rects={null}
192-
<Suspense name="App" rects={null}>
193-
`);
189+
if (isLegacySuspense) {
190+
expect(store).toMatchInlineSnapshot(`
191+
[root]
192+
▾ <App>
193+
▾ <Suspense>
194+
<Lazy>
195+
[suspense-root] rects={null}
196+
<Suspense name="App" rects={null}>
197+
`);
198+
} else {
199+
expect(store).toMatchInlineSnapshot(`
200+
[root]
201+
▾ <App>
202+
<Suspense>
203+
[suspense-root] rects={null}
204+
<Suspense name="App" rects={null}>
205+
`);
206+
}
194207
utils.act(() => legacyRender(<App renderChildren={true} />));
195208
expect(store).toMatchInlineSnapshot(`
196209
[root]
@@ -218,7 +231,13 @@ describe('commit tree', () => {
218231
);
219232
}
220233

221-
expect(commitTrees[0].nodes.size).toBe(3); // <Root> + <App> + <Suspense>
234+
expect(commitTrees[0].nodes.size).toBe(
235+
isLegacySuspense
236+
? // <Root> + <App> + <Suspense> + <Lazy>
237+
4
238+
: // <Root> + <App> + <Suspense>
239+
3,
240+
);
222241
expect(commitTrees[1].nodes.size).toBe(4); // <Root> + <App> + <Suspense> + <LazyInnerComponent>
223242
expect(commitTrees[2].nodes.size).toBe(2); // <Root> + <App>
224243
});
@@ -272,13 +291,24 @@ describe('commit tree', () => {
272291
it('should support Lazy components that are unmounted before resolving (legacy render)', async () => {
273292
utils.act(() => store.profilerStore.startProfiling());
274293
utils.act(() => legacyRender(<App renderChildren={true} />));
275-
expect(store).toMatchInlineSnapshot(`
276-
[root]
277-
▾ <App>
278-
<Suspense>
279-
[suspense-root] rects={null}
280-
<Suspense name="App" rects={null}>
281-
`);
294+
if (isLegacySuspense) {
295+
expect(store).toMatchInlineSnapshot(`
296+
[root]
297+
▾ <App>
298+
▾ <Suspense>
299+
<Lazy>
300+
[suspense-root] rects={null}
301+
<Suspense name="App" rects={null}>
302+
`);
303+
} else {
304+
expect(store).toMatchInlineSnapshot(`
305+
[root]
306+
▾ <App>
307+
<Suspense>
308+
[suspense-root] rects={null}
309+
<Suspense name="App" rects={null}>
310+
`);
311+
}
282312
utils.act(() => legacyRender(<App renderChildren={false} />));
283313
expect(store).toMatchInlineSnapshot(`
284314
[root]
@@ -297,7 +327,13 @@ describe('commit tree', () => {
297327
);
298328
}
299329

300-
expect(commitTrees[0].nodes.size).toBe(3); // <Root> + <App> + <Suspense>
330+
expect(commitTrees[0].nodes.size).toBe(
331+
isLegacySuspense
332+
? // <Root> + <App> + <Suspense> + <Lazy>
333+
4
334+
: // <Root> + <App> + <Suspense>
335+
3,
336+
);
301337
expect(commitTrees[1].nodes.size).toBe(2); // <Root> + <App>
302338
});
303339

0 commit comments

Comments
 (0)