88 */
99
1010import type Store from 'react-devtools-shared/src/devtools/store' ;
11+ import {
12+ getLegacyRenderImplementation ,
13+ getModernRenderImplementation ,
14+ } from './utils' ;
1115
1216describe ( 'commit tree' , ( ) => {
1317 let React ;
14- let ReactDOMClient ;
1518 let Scheduler ;
16- let legacyRender ;
1719 let store : Store ;
1820 let utils ;
1921
2022 beforeEach ( ( ) => {
2123 utils = require ( './utils' ) ;
2224 utils . beforeEachProfiling ( ) ;
2325
24- legacyRender = utils . legacyRender ;
25-
2626 store = global . store ;
2727 store . collapseNodesByDefault = false ;
2828 store . recordChangeDescriptions = true ;
2929
3030 React = require ( 'react' ) ;
31- ReactDOMClient = require ( 'react-dom/client' ) ;
3231 Scheduler = require ( 'scheduler' ) ;
3332 } ) ;
3433
34+ const { render : legacyRender } = getLegacyRenderImplementation ( ) ;
35+ const { render : modernRender } = getModernRenderImplementation ( ) ;
36+
3537 // @reactVersion >= 16.9
38+ // @reactVersion < 19
3639 it ( 'should be able to rebuild the store tree for each commit' , ( ) => {
3740 const Parent = ( { count} ) => {
3841 Scheduler . unstable_advanceTime ( 10 ) ;
@@ -45,31 +48,29 @@ describe('commit tree', () => {
4548 return null ;
4649 } ) ;
4750
48- const container = document . createElement ( 'div' ) ;
49-
5051 utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
51- utils . act ( ( ) => legacyRender ( < Parent count = { 1 } /> , container ) ) ;
52+ utils . act ( ( ) => legacyRender ( < Parent count = { 1 } /> ) ) ;
5253 expect ( store ) . toMatchInlineSnapshot ( `
5354 [root]
5455 ▾ <Parent>
5556 <Child key="0"> [Memo]
5657 ` ) ;
57- utils . act ( ( ) => legacyRender ( < Parent count = { 3 } /> , container ) ) ;
58+ utils . act ( ( ) => legacyRender ( < Parent count = { 3 } /> ) ) ;
5859 expect ( store ) . toMatchInlineSnapshot ( `
5960 [root]
6061 ▾ <Parent>
6162 <Child key="0"> [Memo]
6263 <Child key="1"> [Memo]
6364 <Child key="2"> [Memo]
6465 ` ) ;
65- utils . act ( ( ) => legacyRender ( < Parent count = { 2 } /> , container ) ) ;
66+ utils . act ( ( ) => legacyRender ( < Parent count = { 2 } /> ) ) ;
6667 expect ( store ) . toMatchInlineSnapshot ( `
6768 [root]
6869 ▾ <Parent>
6970 <Child key="0"> [Memo]
7071 <Child key="1"> [Memo]
7172 ` ) ;
72- utils . act ( ( ) => legacyRender ( < Parent count = { 0 } /> , container ) ) ;
73+ utils . act ( ( ) => legacyRender ( < Parent count = { 0 } /> ) ) ;
7374 expect ( store ) . toMatchInlineSnapshot ( `
7475 [root]
7576 <Parent>
@@ -118,25 +119,24 @@ describe('commit tree', () => {
118119 } ) ;
119120
120121 // @reactVersion >= 16.9
122+ // @reactVersion < 19
121123 it ( 'should support Lazy components (legacy render)' , async ( ) => {
122- const container = document . createElement ( 'div' ) ;
123-
124124 utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
125- utils . act ( ( ) => legacyRender ( < App renderChildren = { true } /> , container ) ) ;
125+ utils . act ( ( ) => legacyRender ( < App renderChildren = { true } /> ) ) ;
126126 await Promise . resolve ( ) ;
127127 expect ( store ) . toMatchInlineSnapshot ( `
128128 [root]
129129 ▾ <App>
130130 <Suspense>
131131 ` ) ;
132- utils . act ( ( ) => legacyRender ( < App renderChildren = { true } /> , container ) ) ;
132+ utils . act ( ( ) => legacyRender ( < App renderChildren = { true } /> ) ) ;
133133 expect ( store ) . toMatchInlineSnapshot ( `
134134 [root]
135135 ▾ <App>
136136 ▾ <Suspense>
137137 <LazyInnerComponent>
138138 ` ) ;
139- utils . act ( ( ) => legacyRender ( < App renderChildren = { false } /> , container ) ) ;
139+ utils . act ( ( ) => legacyRender ( < App renderChildren = { false } /> ) ) ;
140140 expect ( store ) . toMatchInlineSnapshot ( `
141141 [root]
142142 <App>
@@ -161,25 +161,22 @@ describe('commit tree', () => {
161161
162162 // @reactVersion >= 18.0
163163 it ( 'should support Lazy components (createRoot)' , async ( ) => {
164- const container = document . createElement ( 'div' ) ;
165- const root = ReactDOMClient . createRoot ( container ) ;
166-
167164 utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
168- utils . act ( ( ) => root . render ( < App renderChildren = { true } /> ) ) ;
165+ utils . act ( ( ) => modernRender ( < App renderChildren = { true } /> ) ) ;
169166 await Promise . resolve ( ) ;
170167 expect ( store ) . toMatchInlineSnapshot ( `
171168 [root]
172169 ▾ <App>
173170 <Suspense>
174171 ` ) ;
175- utils . act ( ( ) => root . render ( < App renderChildren = { true } /> ) ) ;
172+ utils . act ( ( ) => modernRender ( < App renderChildren = { true } /> ) ) ;
176173 expect ( store ) . toMatchInlineSnapshot ( `
177174 [root]
178175 ▾ <App>
179176 ▾ <Suspense>
180177 <LazyInnerComponent>
181178 ` ) ;
182- utils . act ( ( ) => root . render ( < App renderChildren = { false } /> ) ) ;
179+ utils . act ( ( ) => modernRender ( < App renderChildren = { false } /> ) ) ;
183180 expect ( store ) . toMatchInlineSnapshot ( `
184181 [root]
185182 <App>
@@ -203,17 +200,16 @@ describe('commit tree', () => {
203200 } ) ;
204201
205202 // @reactVersion >= 16.9
203+ // @reactVersion < 19
206204 it ( 'should support Lazy components that are unmounted before resolving (legacy render)' , async ( ) => {
207- const container = document . createElement ( 'div' ) ;
208-
209205 utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
210- utils . act ( ( ) => legacyRender ( < App renderChildren = { true } /> , container ) ) ;
206+ utils . act ( ( ) => legacyRender ( < App renderChildren = { true } /> ) ) ;
211207 expect ( store ) . toMatchInlineSnapshot ( `
212208 [root]
213209 ▾ <App>
214210 <Suspense>
215211 ` ) ;
216- utils . act ( ( ) => legacyRender ( < App renderChildren = { false } /> , container ) ) ;
212+ utils . act ( ( ) => legacyRender ( < App renderChildren = { false } /> ) ) ;
217213 expect ( store ) . toMatchInlineSnapshot ( `
218214 [root]
219215 <App>
@@ -237,17 +233,14 @@ describe('commit tree', () => {
237233
238234 // @reactVersion >= 18.0
239235 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-
243236 utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
244- utils . act ( ( ) => root . render ( < App renderChildren = { true } /> ) ) ;
237+ utils . act ( ( ) => modernRender ( < App renderChildren = { true } /> ) ) ;
245238 expect ( store ) . toMatchInlineSnapshot ( `
246239 [root]
247240 ▾ <App>
248241 <Suspense>
249242 ` ) ;
250- utils . act ( ( ) => root . render ( < App renderChildren = { false } /> ) ) ;
243+ utils . act ( ( ) => modernRender ( < App renderChildren = { false } /> ) ) ;
251244 expect ( store ) . toMatchInlineSnapshot ( `
252245 [root]
253246 <App>
0 commit comments