Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 460326b

Browse files
committedFeb 2, 2024
chore: use versioned render in profilingCommitTreeBuilder test and gate some for legacy rendering
1 parent e51cda5 commit 460326b

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed
 

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

+24-29
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@
88
*/
99

1010
import type Store from 'react-devtools-shared/src/devtools/store';
11+
import {
12+
getLegacyRenderImplementation,
13+
getModernRenderImplementation,
14+
} from './utils';
1115

1216
describe('commit tree', () => {
1317
let React;
1418
let ReactDOMClient;
1519
let Scheduler;
16-
let legacyRender;
1720
let store: Store;
1821
let utils;
1922

2023
beforeEach(() => {
2124
utils = require('./utils');
2225
utils.beforeEachProfiling();
2326

24-
legacyRender = utils.legacyRender;
25-
2627
store = global.store;
2728
store.collapseNodesByDefault = false;
2829
store.recordChangeDescriptions = true;
@@ -32,7 +33,11 @@ describe('commit tree', () => {
3233
Scheduler = require('scheduler');
3334
});
3435

36+
const {render: legacyRender} = getLegacyRenderImplementation();
37+
const {render: modernRender} = getModernRenderImplementation();
38+
3539
// @reactVersion >= 16.9
40+
// @reactVersion < 19
3641
it('should be able to rebuild the store tree for each commit', () => {
3742
const Parent = ({count}) => {
3843
Scheduler.unstable_advanceTime(10);
@@ -45,31 +50,29 @@ describe('commit tree', () => {
4550
return null;
4651
});
4752

48-
const container = document.createElement('div');
49-
5053
utils.act(() => store.profilerStore.startProfiling());
51-
utils.act(() => legacyRender(<Parent count={1} />, container));
54+
utils.act(() => legacyRender(<Parent count={1} />));
5255
expect(store).toMatchInlineSnapshot(`
5356
[root]
5457
▾ <Parent>
5558
<Child key="0"> [Memo]
5659
`);
57-
utils.act(() => legacyRender(<Parent count={3} />, container));
60+
utils.act(() => legacyRender(<Parent count={3} />));
5861
expect(store).toMatchInlineSnapshot(`
5962
[root]
6063
▾ <Parent>
6164
<Child key="0"> [Memo]
6265
<Child key="1"> [Memo]
6366
<Child key="2"> [Memo]
6467
`);
65-
utils.act(() => legacyRender(<Parent count={2} />, container));
68+
utils.act(() => legacyRender(<Parent count={2} />));
6669
expect(store).toMatchInlineSnapshot(`
6770
[root]
6871
▾ <Parent>
6972
<Child key="0"> [Memo]
7073
<Child key="1"> [Memo]
7174
`);
72-
utils.act(() => legacyRender(<Parent count={0} />, container));
75+
utils.act(() => legacyRender(<Parent count={0} />));
7376
expect(store).toMatchInlineSnapshot(`
7477
[root]
7578
<Parent>
@@ -118,25 +121,24 @@ describe('commit tree', () => {
118121
});
119122

120123
// @reactVersion >= 16.9
124+
// @reactVersion < 19
121125
it('should support Lazy components (legacy render)', async () => {
122-
const container = document.createElement('div');
123-
124126
utils.act(() => store.profilerStore.startProfiling());
125-
utils.act(() => legacyRender(<App renderChildren={true} />, container));
127+
utils.act(() => legacyRender(<App renderChildren={true} />));
126128
await Promise.resolve();
127129
expect(store).toMatchInlineSnapshot(`
128130
[root]
129131
▾ <App>
130132
<Suspense>
131133
`);
132-
utils.act(() => legacyRender(<App renderChildren={true} />, container));
134+
utils.act(() => legacyRender(<App renderChildren={true} />));
133135
expect(store).toMatchInlineSnapshot(`
134136
[root]
135137
▾ <App>
136138
▾ <Suspense>
137139
<LazyInnerComponent>
138140
`);
139-
utils.act(() => legacyRender(<App renderChildren={false} />, container));
141+
utils.act(() => legacyRender(<App renderChildren={false} />));
140142
expect(store).toMatchInlineSnapshot(`
141143
[root]
142144
<App>
@@ -161,25 +163,22 @@ describe('commit tree', () => {
161163

162164
// @reactVersion >= 18.0
163165
it('should support Lazy components (createRoot)', async () => {
164-
const container = document.createElement('div');
165-
const root = ReactDOMClient.createRoot(container);
166-
167166
utils.act(() => store.profilerStore.startProfiling());
168-
utils.act(() => root.render(<App renderChildren={true} />));
167+
utils.act(() => modernRender(<App renderChildren={true} />));
169168
await Promise.resolve();
170169
expect(store).toMatchInlineSnapshot(`
171170
[root]
172171
▾ <App>
173172
<Suspense>
174173
`);
175-
utils.act(() => root.render(<App renderChildren={true} />));
174+
utils.act(() => modernRender(<App renderChildren={true} />));
176175
expect(store).toMatchInlineSnapshot(`
177176
[root]
178177
▾ <App>
179178
▾ <Suspense>
180179
<LazyInnerComponent>
181180
`);
182-
utils.act(() => root.render(<App renderChildren={false} />));
181+
utils.act(() => modernRender(<App renderChildren={false} />));
183182
expect(store).toMatchInlineSnapshot(`
184183
[root]
185184
<App>
@@ -203,17 +202,16 @@ describe('commit tree', () => {
203202
});
204203

205204
// @reactVersion >= 16.9
205+
// @reactVersion < 19
206206
it('should support Lazy components that are unmounted before resolving (legacy render)', async () => {
207-
const container = document.createElement('div');
208-
209207
utils.act(() => store.profilerStore.startProfiling());
210-
utils.act(() => legacyRender(<App renderChildren={true} />, container));
208+
utils.act(() => legacyRender(<App renderChildren={true} />));
211209
expect(store).toMatchInlineSnapshot(`
212210
[root]
213211
▾ <App>
214212
<Suspense>
215213
`);
216-
utils.act(() => legacyRender(<App renderChildren={false} />, container));
214+
utils.act(() => legacyRender(<App renderChildren={false} />));
217215
expect(store).toMatchInlineSnapshot(`
218216
[root]
219217
<App>
@@ -237,17 +235,14 @@ describe('commit tree', () => {
237235

238236
// @reactVersion >= 18.0
239237
it('should support Lazy components that are unmounted before resolving (createRoot)', async () => {
240-
const container = document.createElement('div');
241-
const root = ReactDOMClient.createRoot(container);
242-
243238
utils.act(() => store.profilerStore.startProfiling());
244-
utils.act(() => root.render(<App renderChildren={true} />));
239+
utils.act(() => modernRender(<App renderChildren={true} />));
245240
expect(store).toMatchInlineSnapshot(`
246241
[root]
247242
▾ <App>
248243
<Suspense>
249244
`);
250-
utils.act(() => root.render(<App renderChildren={false} />));
245+
utils.act(() => modernRender(<App renderChildren={false} />));
251246
expect(store).toMatchInlineSnapshot(`
252247
[root]
253248
<App>

0 commit comments

Comments
 (0)
Please sign in to comment.