8
8
*/
9
9
10
10
import type Store from 'react-devtools-shared/src/devtools/store' ;
11
+ import {
12
+ getLegacyRenderImplementation ,
13
+ getModernRenderImplementation ,
14
+ } from './utils' ;
11
15
12
16
describe ( 'commit tree' , ( ) => {
13
17
let React ;
14
18
let ReactDOMClient ;
15
19
let Scheduler ;
16
- let legacyRender ;
17
20
let store : Store ;
18
21
let utils ;
19
22
20
23
beforeEach ( ( ) => {
21
24
utils = require ( './utils' ) ;
22
25
utils . beforeEachProfiling ( ) ;
23
26
24
- legacyRender = utils . legacyRender ;
25
-
26
27
store = global . store ;
27
28
store . collapseNodesByDefault = false ;
28
29
store . recordChangeDescriptions = true ;
@@ -32,7 +33,11 @@ describe('commit tree', () => {
32
33
Scheduler = require ( 'scheduler' ) ;
33
34
} ) ;
34
35
36
+ const { render : legacyRender } = getLegacyRenderImplementation ( ) ;
37
+ const { render : modernRender } = getModernRenderImplementation ( ) ;
38
+
35
39
// @reactVersion >= 16.9
40
+ // @reactVersion < 19
36
41
it ( 'should be able to rebuild the store tree for each commit' , ( ) => {
37
42
const Parent = ( { count} ) => {
38
43
Scheduler . unstable_advanceTime ( 10 ) ;
@@ -45,31 +50,29 @@ describe('commit tree', () => {
45
50
return null ;
46
51
} ) ;
47
52
48
- const container = document . createElement ( 'div' ) ;
49
-
50
53
utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
51
- utils . act ( ( ) => legacyRender ( < Parent count = { 1 } /> , container ) ) ;
54
+ utils . act ( ( ) => legacyRender ( < Parent count = { 1 } /> ) ) ;
52
55
expect ( store ) . toMatchInlineSnapshot ( `
53
56
[root]
54
57
▾ <Parent>
55
58
<Child key="0"> [Memo]
56
59
` ) ;
57
- utils . act ( ( ) => legacyRender ( < Parent count = { 3 } /> , container ) ) ;
60
+ utils . act ( ( ) => legacyRender ( < Parent count = { 3 } /> ) ) ;
58
61
expect ( store ) . toMatchInlineSnapshot ( `
59
62
[root]
60
63
▾ <Parent>
61
64
<Child key="0"> [Memo]
62
65
<Child key="1"> [Memo]
63
66
<Child key="2"> [Memo]
64
67
` ) ;
65
- utils . act ( ( ) => legacyRender ( < Parent count = { 2 } /> , container ) ) ;
68
+ utils . act ( ( ) => legacyRender ( < Parent count = { 2 } /> ) ) ;
66
69
expect ( store ) . toMatchInlineSnapshot ( `
67
70
[root]
68
71
▾ <Parent>
69
72
<Child key="0"> [Memo]
70
73
<Child key="1"> [Memo]
71
74
` ) ;
72
- utils . act ( ( ) => legacyRender ( < Parent count = { 0 } /> , container ) ) ;
75
+ utils . act ( ( ) => legacyRender ( < Parent count = { 0 } /> ) ) ;
73
76
expect ( store ) . toMatchInlineSnapshot ( `
74
77
[root]
75
78
<Parent>
@@ -118,25 +121,24 @@ describe('commit tree', () => {
118
121
} ) ;
119
122
120
123
// @reactVersion >= 16.9
124
+ // @reactVersion < 19
121
125
it ( 'should support Lazy components (legacy render)' , async ( ) => {
122
- const container = document . createElement ( 'div' ) ;
123
-
124
126
utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
125
- utils . act ( ( ) => legacyRender ( < App renderChildren = { true } /> , container ) ) ;
127
+ utils . act ( ( ) => legacyRender ( < App renderChildren = { true } /> ) ) ;
126
128
await Promise . resolve ( ) ;
127
129
expect ( store ) . toMatchInlineSnapshot ( `
128
130
[root]
129
131
▾ <App>
130
132
<Suspense>
131
133
` ) ;
132
- utils . act ( ( ) => legacyRender ( < App renderChildren = { true } /> , container ) ) ;
134
+ utils . act ( ( ) => legacyRender ( < App renderChildren = { true } /> ) ) ;
133
135
expect ( store ) . toMatchInlineSnapshot ( `
134
136
[root]
135
137
▾ <App>
136
138
▾ <Suspense>
137
139
<LazyInnerComponent>
138
140
` ) ;
139
- utils . act ( ( ) => legacyRender ( < App renderChildren = { false } /> , container ) ) ;
141
+ utils . act ( ( ) => legacyRender ( < App renderChildren = { false } /> ) ) ;
140
142
expect ( store ) . toMatchInlineSnapshot ( `
141
143
[root]
142
144
<App>
@@ -161,25 +163,22 @@ describe('commit tree', () => {
161
163
162
164
// @reactVersion >= 18.0
163
165
it ( 'should support Lazy components (createRoot)' , async ( ) => {
164
- const container = document . createElement ( 'div' ) ;
165
- const root = ReactDOMClient . createRoot ( container ) ;
166
-
167
166
utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
168
- utils . act ( ( ) => root . render ( < App renderChildren = { true } /> ) ) ;
167
+ utils . act ( ( ) => modernRender ( < App renderChildren = { true } /> ) ) ;
169
168
await Promise . resolve ( ) ;
170
169
expect ( store ) . toMatchInlineSnapshot ( `
171
170
[root]
172
171
▾ <App>
173
172
<Suspense>
174
173
` ) ;
175
- utils . act ( ( ) => root . render ( < App renderChildren = { true } /> ) ) ;
174
+ utils . act ( ( ) => modernRender ( < App renderChildren = { true } /> ) ) ;
176
175
expect ( store ) . toMatchInlineSnapshot ( `
177
176
[root]
178
177
▾ <App>
179
178
▾ <Suspense>
180
179
<LazyInnerComponent>
181
180
` ) ;
182
- utils . act ( ( ) => root . render ( < App renderChildren = { false } /> ) ) ;
181
+ utils . act ( ( ) => modernRender ( < App renderChildren = { false } /> ) ) ;
183
182
expect ( store ) . toMatchInlineSnapshot ( `
184
183
[root]
185
184
<App>
@@ -203,17 +202,16 @@ describe('commit tree', () => {
203
202
} ) ;
204
203
205
204
// @reactVersion >= 16.9
205
+ // @reactVersion < 19
206
206
it ( 'should support Lazy components that are unmounted before resolving (legacy render)' , async ( ) => {
207
- const container = document . createElement ( 'div' ) ;
208
-
209
207
utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
210
- utils . act ( ( ) => legacyRender ( < App renderChildren = { true } /> , container ) ) ;
208
+ utils . act ( ( ) => legacyRender ( < App renderChildren = { true } /> ) ) ;
211
209
expect ( store ) . toMatchInlineSnapshot ( `
212
210
[root]
213
211
▾ <App>
214
212
<Suspense>
215
213
` ) ;
216
- utils . act ( ( ) => legacyRender ( < App renderChildren = { false } /> , container ) ) ;
214
+ utils . act ( ( ) => legacyRender ( < App renderChildren = { false } /> ) ) ;
217
215
expect ( store ) . toMatchInlineSnapshot ( `
218
216
[root]
219
217
<App>
@@ -237,17 +235,14 @@ describe('commit tree', () => {
237
235
238
236
// @reactVersion >= 18.0
239
237
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
-
243
238
utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
244
- utils . act ( ( ) => root . render ( < App renderChildren = { true } /> ) ) ;
239
+ utils . act ( ( ) => modernRender ( < App renderChildren = { true } /> ) ) ;
245
240
expect ( store ) . toMatchInlineSnapshot ( `
246
241
[root]
247
242
▾ <App>
248
243
<Suspense>
249
244
` ) ;
250
- utils . act ( ( ) => root . render ( < App renderChildren = { false } /> ) ) ;
245
+ utils . act ( ( ) => modernRender ( < App renderChildren = { false } /> ) ) ;
251
246
expect ( store ) . toMatchInlineSnapshot ( `
252
247
[root]
253
248
<App>
0 commit comments