99
1010import type Store from 'react-devtools-shared/src/devtools/store' ;
1111
12- import {
13- getLegacyRenderImplementation ,
14- getModernRenderImplementation ,
15- } from './utils' ;
12+ import { getVersionedRenderImplementation } from './utils' ;
1613
1714describe ( 'commit tree' , ( ) => {
1815 let React = require ( 'react' ) ;
@@ -32,12 +29,10 @@ describe('commit tree', () => {
3229 Scheduler = require ( 'scheduler' ) ;
3330 } ) ;
3431
35- const { render : legacyRender } = getLegacyRenderImplementation ( ) ;
36- const { render : modernRender } = getModernRenderImplementation ( ) ;
32+ const { render} = getVersionedRenderImplementation ( ) ;
3733
3834 // @reactVersion >= 16.9
39- // @reactVersion <= 18.2
40- it ( 'should be able to rebuild the store tree for each commit (legacy render)' , ( ) => {
35+ it ( 'should be able to rebuild the store tree for each commit' , ( ) => {
4136 const Parent = ( { count} ) => {
4237 Scheduler . unstable_advanceTime ( 10 ) ;
4338 return new Array ( count )
@@ -50,87 +45,28 @@ describe('commit tree', () => {
5045 } ) ;
5146
5247 utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
53- utils . act ( ( ) => legacyRender ( < Parent count = { 1 } /> ) ) ;
48+ utils . act ( ( ) => render ( < Parent count = { 1 } /> ) ) ;
5449 expect ( store ) . toMatchInlineSnapshot ( `
5550 [root]
5651 ▾ <Parent>
5752 <Child key="0"> [Memo]
5853 ` ) ;
59- utils . act ( ( ) => legacyRender ( < Parent count = { 3 } /> ) ) ;
54+ utils . act ( ( ) => render ( < Parent count = { 3 } /> ) ) ;
6055 expect ( store ) . toMatchInlineSnapshot ( `
6156 [root]
6257 ▾ <Parent>
6358 <Child key="0"> [Memo]
6459 <Child key="1"> [Memo]
6560 <Child key="2"> [Memo]
6661 ` ) ;
67- utils . act ( ( ) => legacyRender ( < Parent count = { 2 } /> ) ) ;
62+ utils . act ( ( ) => render ( < Parent count = { 2 } /> ) ) ;
6863 expect ( store ) . toMatchInlineSnapshot ( `
6964 [root]
7065 ▾ <Parent>
7166 <Child key="0"> [Memo]
7267 <Child key="1"> [Memo]
7368 ` ) ;
74- utils . act ( ( ) => legacyRender ( < Parent count = { 0 } /> ) ) ;
75- expect ( store ) . toMatchInlineSnapshot ( `
76- [root]
77- <Parent>
78- ` ) ;
79- utils . act ( ( ) => store . profilerStore . stopProfiling ( ) ) ;
80-
81- const rootID = store . roots [ 0 ] ;
82- const commitTrees = [ ] ;
83- for ( let commitIndex = 0 ; commitIndex < 4 ; commitIndex ++ ) {
84- commitTrees . push (
85- store . profilerStore . profilingCache . getCommitTree ( {
86- commitIndex,
87- rootID,
88- } ) ,
89- ) ;
90- }
91-
92- expect ( commitTrees [ 0 ] . nodes . size ) . toBe ( 3 ) ; // <Root> + <Parent> + <Child>
93- expect ( commitTrees [ 1 ] . nodes . size ) . toBe ( 5 ) ; // <Root> + <Parent> + <Child> x 3
94- expect ( commitTrees [ 2 ] . nodes . size ) . toBe ( 4 ) ; // <Root> + <Parent> + <Child> x 2
95- expect ( commitTrees [ 3 ] . nodes . size ) . toBe ( 2 ) ; // <Root> + <Parent>
96- } ) ;
97-
98- // @reactVersion >= 18
99- it ( 'should be able to rebuild the store tree for each commit (createRoot)' , ( ) => {
100- const Parent = ( { count} ) => {
101- Scheduler . unstable_advanceTime ( 10 ) ;
102- return new Array ( count )
103- . fill ( true )
104- . map ( ( _ , index ) => < Child key = { index } /> ) ;
105- } ;
106- const Child = React . memo ( function Child ( ) {
107- Scheduler . unstable_advanceTime ( 2 ) ;
108- return null ;
109- } ) ;
110-
111- utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
112- utils . act ( ( ) => modernRender ( < Parent count = { 1 } /> ) ) ;
113- expect ( store ) . toMatchInlineSnapshot ( `
114- [root]
115- ▾ <Parent>
116- <Child key="0"> [Memo]
117- ` ) ;
118- utils . act ( ( ) => modernRender ( < Parent count = { 3 } /> ) ) ;
119- expect ( store ) . toMatchInlineSnapshot ( `
120- [root]
121- ▾ <Parent>
122- <Child key="0"> [Memo]
123- <Child key="1"> [Memo]
124- <Child key="2"> [Memo]
125- ` ) ;
126- utils . act ( ( ) => modernRender ( < Parent count = { 2 } /> ) ) ;
127- expect ( store ) . toMatchInlineSnapshot ( `
128- [root]
129- ▾ <Parent>
130- <Child key="0"> [Memo]
131- <Child key="1"> [Memo]
132- ` ) ;
133- utils . act ( ( ) => modernRender ( < Parent count = { 0 } /> ) ) ;
69+ utils . act ( ( ) => render ( < Parent count = { 0 } /> ) ) ;
13470 expect ( store ) . toMatchInlineSnapshot ( `
13571 [root]
13672 <Parent>
@@ -179,10 +115,9 @@ describe('commit tree', () => {
179115 } ) ;
180116
181117 // @reactVersion >= 16.9
182- // @reactVersion <= 18.2
183- it ( 'should support Lazy components (legacy render)' , async ( ) => {
118+ it ( 'should support Lazy components' , async ( ) => {
184119 utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
185- utils . act ( ( ) => legacyRender ( < App renderChildren = { true } /> ) ) ;
120+ utils . act ( ( ) => render ( < App renderChildren = { true } /> ) ) ;
186121 await Promise . resolve ( ) ;
187122 expect ( store ) . toMatchInlineSnapshot ( `
188123 [root]
@@ -191,7 +126,7 @@ describe('commit tree', () => {
191126 [suspense-root] rects={null}
192127 <Suspense name="App" rects={null}>
193128 ` ) ;
194- utils . act ( ( ) => legacyRender ( < App renderChildren = { true } /> ) ) ;
129+ utils . act ( ( ) => render ( < App renderChildren = { true } /> ) ) ;
195130 expect ( store ) . toMatchInlineSnapshot ( `
196131 [root]
197132 ▾ <App>
@@ -200,7 +135,7 @@ describe('commit tree', () => {
200135 [suspense-root] rects={null}
201136 <Suspense name="App" rects={null}>
202137 ` ) ;
203- utils . act ( ( ) => legacyRender ( < App renderChildren = { false } /> ) ) ;
138+ utils . act ( ( ) => render ( < App renderChildren = { false } /> ) ) ;
204139 expect ( store ) . toMatchInlineSnapshot ( `
205140 [root]
206141 <App>
@@ -223,63 +158,18 @@ describe('commit tree', () => {
223158 expect ( commitTrees [ 2 ] . nodes . size ) . toBe ( 2 ) ; // <Root> + <App>
224159 } ) ;
225160
226- // @reactVersion >= 18.0
227- it ( 'should support Lazy components (createRoot)' , async ( ) => {
228- utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
229- utils . act ( ( ) => modernRender ( < App renderChildren = { true } /> ) ) ;
230- await Promise . resolve ( ) ;
231- expect ( store ) . toMatchInlineSnapshot ( `
232- [root]
233- ▾ <App>
234- <Suspense>
235- [suspense-root] rects={null}
236- <Suspense name="App" rects={null}>
237- ` ) ;
238- utils . act ( ( ) => modernRender ( < App renderChildren = { true } /> ) ) ;
239- expect ( store ) . toMatchInlineSnapshot ( `
240- [root]
241- ▾ <App>
242- ▾ <Suspense>
243- <LazyInnerComponent>
244- [suspense-root] rects={null}
245- <Suspense name="App" rects={null}>
246- ` ) ;
247- utils . act ( ( ) => modernRender ( < App renderChildren = { false } /> ) ) ;
248- expect ( store ) . toMatchInlineSnapshot ( `
249- [root]
250- <App>
251- ` ) ;
252- utils . act ( ( ) => store . profilerStore . stopProfiling ( ) ) ;
253-
254- const rootID = store . roots [ 0 ] ;
255- const commitTrees = [ ] ;
256- for ( let commitIndex = 0 ; commitIndex < 3 ; commitIndex ++ ) {
257- commitTrees . push (
258- store . profilerStore . profilingCache . getCommitTree ( {
259- commitIndex,
260- rootID,
261- } ) ,
262- ) ;
263- }
264-
265- expect ( commitTrees [ 0 ] . nodes . size ) . toBe ( 3 ) ; // <Root> + <App> + <Suspense>
266- expect ( commitTrees [ 1 ] . nodes . size ) . toBe ( 4 ) ; // <Root> + <App> + <Suspense> + <LazyInnerComponent>
267- expect ( commitTrees [ 2 ] . nodes . size ) . toBe ( 2 ) ; // <Root> + <App>
268- } ) ;
269-
270161 // @reactVersion >= 16.9
271- // @reactVersion <= 18.2
272- it ( 'should support Lazy components that are unmounted before resolving (legacy render)' , async ( ) => {
162+ it ( 'should support Lazy components that are unmounted before resolving' , async ( ) => {
273163 utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
274- utils . act ( ( ) => legacyRender ( < App renderChildren = { true } /> ) ) ;
164+ utils . act ( ( ) => render ( < App renderChildren = { true } /> ) ) ;
275165 expect ( store ) . toMatchInlineSnapshot ( `
276166 [root]
277167 ▾ <App>
278168 <Suspense>
279169 [suspense-root] rects={null}
280170 <Suspense name="App" rects={null}>
281171 ` ) ;
282- utils . act ( ( ) => legacyRender ( < App renderChildren = { false } /> ) ) ;
172+ utils . act ( ( ) => render ( < App renderChildren = { false } /> ) ) ;
283173 expect ( store ) . toMatchInlineSnapshot ( `
284174 [root]
285175 <App>
@@ -300,38 +190,5 @@ describe('commit tree', () => {
300190 expect ( commitTrees [ 0 ] . nodes . size ) . toBe ( 3 ) ;
301191 expect ( commitTrees [ 1 ] . nodes . size ) . toBe ( 2 ) ; // <Root> + <App>
302192 } ) ;
303-
304- // @reactVersion >= 18.0
305- it ( 'should support Lazy components that are unmounted before resolving (createRoot)' , async ( ) => {
306- utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
307- utils . act ( ( ) => modernRender ( < App renderChildren = { true } /> ) ) ;
308- expect ( store ) . toMatchInlineSnapshot ( `
309- [root]
310- ▾ <App>
311- <Suspense>
312- [suspense-root] rects={null}
313- <Suspense name="App" rects={null}>
314- ` ) ;
315- utils . act ( ( ) => modernRender ( < App renderChildren = { false } /> ) ) ;
316- expect ( store ) . toMatchInlineSnapshot ( `
317- [root]
318- <App>
319- ` ) ;
320- utils . act ( ( ) => store . profilerStore . stopProfiling ( ) ) ;
321-
322- const rootID = store . roots [ 0 ] ;
323- const commitTrees = [ ] ;
324- for ( let commitIndex = 0 ; commitIndex < 2 ; commitIndex ++ ) {
325- commitTrees . push (
326- store . profilerStore . profilingCache . getCommitTree ( {
327- commitIndex,
328- rootID,
329- } ) ,
330- ) ;
331- }
332-
333- expect ( commitTrees [ 0 ] . nodes . size ) . toBe ( 3 ) ; // <Root> + <App> + <Suspense>
334- expect ( commitTrees [ 1 ] . nodes . size ) . toBe ( 2 ) ; // <Root> + <App>
335- } ) ;
336193 } ) ;
337194} ) ;
0 commit comments