@@ -43,35 +43,6 @@ describe('ReactDOMRoot', () => {
4343 expect ( container . textContent ) . toEqual ( '' ) ;
4444 } ) ;
4545
46- it ( '`root.render` returns a thenable work object' , ( ) => {
47- const root = ReactDOM . unstable_createRoot ( container ) ;
48- const work = root . render ( 'Hi' ) ;
49- let ops = [ ] ;
50- work . then ( ( ) => {
51- ops . push ( 'inside callback: ' + container . textContent ) ;
52- } ) ;
53- ops . push ( 'before committing: ' + container . textContent ) ;
54- Scheduler . unstable_flushAll ( ) ;
55- ops . push ( 'after committing: ' + container . textContent ) ;
56- expect ( ops ) . toEqual ( [
57- 'before committing: ' ,
58- // `then` callback should fire during commit phase
59- 'inside callback: Hi' ,
60- 'after committing: Hi' ,
61- ] ) ;
62- } ) ;
63-
64- it ( 'resolves `work.then` callback synchronously if the work already committed' , ( ) => {
65- const root = ReactDOM . unstable_createRoot ( container ) ;
66- const work = root . render ( 'Hi' ) ;
67- Scheduler . unstable_flushAll ( ) ;
68- let ops = [ ] ;
69- work . then ( ( ) => {
70- ops . push ( 'inside callback' ) ;
71- } ) ;
72- expect ( ops ) . toEqual ( [ 'inside callback' ] ) ;
73- } ) ;
74-
7546 it ( 'supports hydration' , async ( ) => {
7647 const markup = await new Promise ( resolve =>
7748 resolve (
@@ -129,200 +100,6 @@ describe('ReactDOMRoot', () => {
129100 expect ( container . textContent ) . toEqual ( 'abdc' ) ;
130101 } ) ;
131102
132- it ( 'can defer a commit by batching it' , ( ) => {
133- const root = ReactDOM . unstable_createRoot ( container ) ;
134- const batch = root . createBatch ( ) ;
135- batch . render ( < div > Hi</ div > ) ;
136- // Hasn't committed yet
137- expect ( container . textContent ) . toEqual ( '' ) ;
138- // Commit
139- batch . commit ( ) ;
140- expect ( container . textContent ) . toEqual ( 'Hi' ) ;
141- } ) ;
142-
143- it ( 'applies setState in componentDidMount synchronously in a batch' , done => {
144- class App extends React . Component {
145- state = { mounted : false } ;
146- componentDidMount ( ) {
147- this . setState ( {
148- mounted : true ,
149- } ) ;
150- }
151- render ( ) {
152- return this . state . mounted ? 'Hi' : 'Bye' ;
153- }
154- }
155-
156- const root = ReactDOM . unstable_createRoot ( container ) ;
157- const batch = root . createBatch ( ) ;
158- batch . render ( < App /> ) ;
159-
160- Scheduler . unstable_flushAll ( ) ;
161-
162- // Hasn't updated yet
163- expect ( container . textContent ) . toEqual ( '' ) ;
164-
165- let ops = [ ] ;
166- batch . then ( ( ) => {
167- // Still hasn't updated
168- ops . push ( container . textContent ) ;
169-
170- // Should synchronously commit
171- batch . commit ( ) ;
172- ops . push ( container . textContent ) ;
173-
174- expect ( ops ) . toEqual ( [ '' , 'Hi' ] ) ;
175- done ( ) ;
176- } ) ;
177- } ) ;
178-
179- it ( 'does not restart a completed batch when committing if there were no intervening updates' , ( ) => {
180- let ops = [ ] ;
181- function Foo ( props ) {
182- ops . push ( 'Foo' ) ;
183- return props . children ;
184- }
185- const root = ReactDOM . unstable_createRoot ( container ) ;
186- const batch = root . createBatch ( ) ;
187- batch . render ( < Foo > Hi</ Foo > ) ;
188- // Flush all async work.
189- Scheduler . unstable_flushAll ( ) ;
190- // Root should complete without committing.
191- expect ( ops ) . toEqual ( [ 'Foo' ] ) ;
192- expect ( container . textContent ) . toEqual ( '' ) ;
193-
194- ops = [ ] ;
195-
196- // Commit. Shouldn't re-render Foo.
197- batch . commit ( ) ;
198- expect ( ops ) . toEqual ( [ ] ) ;
199- expect ( container . textContent ) . toEqual ( 'Hi' ) ;
200- } ) ;
201-
202- it ( 'can wait for a batch to finish' , ( ) => {
203- const root = ReactDOM . unstable_createRoot ( container ) ;
204- const batch = root . createBatch ( ) ;
205- batch . render ( 'Foo' ) ;
206-
207- Scheduler . unstable_flushAll ( ) ;
208-
209- // Hasn't updated yet
210- expect ( container . textContent ) . toEqual ( '' ) ;
211-
212- let ops = [ ] ;
213- batch . then ( ( ) => {
214- // Still hasn't updated
215- ops . push ( container . textContent ) ;
216- // Should synchronously commit
217- batch . commit ( ) ;
218- ops . push ( container . textContent ) ;
219- } ) ;
220-
221- expect ( ops ) . toEqual ( [ '' , 'Foo' ] ) ;
222- } ) ;
223-
224- it ( '`batch.render` returns a thenable work object' , ( ) => {
225- const root = ReactDOM . unstable_createRoot ( container ) ;
226- const batch = root . createBatch ( ) ;
227- const work = batch . render ( 'Hi' ) ;
228- let ops = [ ] ;
229- work . then ( ( ) => {
230- ops . push ( 'inside callback: ' + container . textContent ) ;
231- } ) ;
232- ops . push ( 'before committing: ' + container . textContent ) ;
233- batch . commit ( ) ;
234- ops . push ( 'after committing: ' + container . textContent ) ;
235- expect ( ops ) . toEqual ( [
236- 'before committing: ' ,
237- // `then` callback should fire during commit phase
238- 'inside callback: Hi' ,
239- 'after committing: Hi' ,
240- ] ) ;
241- } ) ;
242-
243- it ( 'can commit an empty batch' , ( ) => {
244- const root = ReactDOM . unstable_createRoot ( container ) ;
245- root . render ( 1 ) ;
246-
247- Scheduler . unstable_advanceTime ( 2000 ) ;
248- // This batch has a later expiration time than the earlier update.
249- const batch = root . createBatch ( ) ;
250-
251- // This should not flush the earlier update.
252- batch . commit ( ) ;
253- expect ( container . textContent ) . toEqual ( '' ) ;
254-
255- Scheduler . unstable_flushAll ( ) ;
256- expect ( container . textContent ) . toEqual ( '1' ) ;
257- } ) ;
258-
259- it ( 'two batches created simultaneously are committed separately' , ( ) => {
260- // (In other words, they have distinct expiration times)
261- const root = ReactDOM . unstable_createRoot ( container ) ;
262- const batch1 = root . createBatch ( ) ;
263- batch1 . render ( 1 ) ;
264- const batch2 = root . createBatch ( ) ;
265- batch2 . render ( 2 ) ;
266-
267- expect ( container . textContent ) . toEqual ( '' ) ;
268-
269- batch1 . commit ( ) ;
270- expect ( container . textContent ) . toEqual ( '1' ) ;
271-
272- batch2 . commit ( ) ;
273- expect ( container . textContent ) . toEqual ( '2' ) ;
274- } ) ;
275-
276- it ( 'commits an earlier batch without committing a later batch' , ( ) => {
277- const root = ReactDOM . unstable_createRoot ( container ) ;
278- const batch1 = root . createBatch ( ) ;
279- batch1 . render ( 1 ) ;
280-
281- // This batch has a later expiration time
282- Scheduler . unstable_advanceTime ( 2000 ) ;
283- const batch2 = root . createBatch ( ) ;
284- batch2 . render ( 2 ) ;
285-
286- expect ( container . textContent ) . toEqual ( '' ) ;
287-
288- batch1 . commit ( ) ;
289- expect ( container . textContent ) . toEqual ( '1' ) ;
290-
291- batch2 . commit ( ) ;
292- expect ( container . textContent ) . toEqual ( '2' ) ;
293- } ) ;
294-
295- it ( 'commits a later batch without committing an earlier batch' , ( ) => {
296- const root = ReactDOM . unstable_createRoot ( container ) ;
297- const batch1 = root . createBatch ( ) ;
298- batch1 . render ( 1 ) ;
299-
300- // This batch has a later expiration time
301- Scheduler . unstable_advanceTime ( 2000 ) ;
302- const batch2 = root . createBatch ( ) ;
303- batch2 . render ( 2 ) ;
304-
305- expect ( container . textContent ) . toEqual ( '' ) ;
306-
307- batch2 . commit ( ) ;
308- expect ( container . textContent ) . toEqual ( '2' ) ;
309-
310- batch1 . commit ( ) ;
311- Scheduler . unstable_flushAll ( ) ;
312- expect ( container . textContent ) . toEqual ( '1' ) ;
313- } ) ;
314-
315- it ( 'handles fatal errors triggered by batch.commit()' , ( ) => {
316- const root = ReactDOM . unstable_createRoot ( container ) ;
317- const batch = root . createBatch ( ) ;
318- const InvalidType = undefined ;
319- expect ( ( ) => batch . render ( < InvalidType /> ) ) . toWarnDev (
320- [ 'React.createElement: type is invalid' ] ,
321- { withoutStack : true } ,
322- ) ;
323- expect ( ( ) => batch . commit ( ) ) . toThrow ( 'Element type is invalid' ) ;
324- } ) ;
325-
326103 it ( 'throws a good message on invalid containers' , ( ) => {
327104 expect ( ( ) => {
328105 ReactDOM . unstable_createRoot ( < div > Hi</ div > ) ;
0 commit comments