@@ -48,6 +48,13 @@ describe('ReactDOMFizzForm', () => {
48
48
document . body . removeChild ( container ) ;
49
49
} ) ;
50
50
51
+ async function serverAct ( callback ) {
52
+ jest . useRealTimers ( ) ;
53
+ await callback ( ) ;
54
+ await new Promise ( r => setTimeout ( r , 1 ) ) ;
55
+ jest . useFakeTimers ( ) ;
56
+ }
57
+
51
58
function submit ( submitter ) {
52
59
const form = submitter . form || submitter ;
53
60
if ( ! submitter . form ) {
@@ -96,8 +103,10 @@ describe('ReactDOMFizzForm', () => {
96
103
) ;
97
104
}
98
105
99
- const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
100
- await readIntoContainer ( stream ) ;
106
+ await serverAct ( async ( ) => {
107
+ const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
108
+ await readIntoContainer ( stream ) ;
109
+ } ) ;
101
110
await act ( async ( ) => {
102
111
ReactDOMClient . hydrateRoot ( container , < App /> ) ;
103
112
} ) ;
@@ -143,8 +152,10 @@ describe('ReactDOMFizzForm', () => {
143
152
) ;
144
153
}
145
154
146
- const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
147
- await readIntoContainer ( stream ) ;
155
+ await serverAct ( async ( ) => {
156
+ const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
157
+ await readIntoContainer ( stream ) ;
158
+ } ) ;
148
159
await act ( async ( ) => {
149
160
ReactDOMClient . hydrateRoot ( container , < App /> ) ;
150
161
} ) ;
@@ -175,8 +186,10 @@ describe('ReactDOMFizzForm', () => {
175
186
) ;
176
187
}
177
188
178
- const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
179
- await readIntoContainer ( stream ) ;
189
+ await serverAct ( async ( ) => {
190
+ const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
191
+ await readIntoContainer ( stream ) ;
192
+ } ) ;
180
193
await expect ( async ( ) => {
181
194
await act ( async ( ) => {
182
195
ReactDOMClient . hydrateRoot ( container , < App isClient = { true } /> ) ;
@@ -197,8 +210,10 @@ describe('ReactDOMFizzForm', () => {
197
210
) ;
198
211
}
199
212
200
- const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
201
- await readIntoContainer ( stream ) ;
213
+ await serverAct ( async ( ) => {
214
+ const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
215
+ await readIntoContainer ( stream ) ;
216
+ } ) ;
202
217
// This should ideally warn because only the client provides a function that doesn't line up.
203
218
await act ( async ( ) => {
204
219
ReactDOMClient . hydrateRoot ( container , < App isClient = { true } /> ) ;
@@ -231,8 +246,10 @@ describe('ReactDOMFizzForm', () => {
231
246
) ;
232
247
}
233
248
234
- const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
235
- await readIntoContainer ( stream ) ;
249
+ await serverAct ( async ( ) => {
250
+ const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
251
+ await readIntoContainer ( stream ) ;
252
+ } ) ;
236
253
let root ;
237
254
await act ( async ( ) => {
238
255
root = ReactDOMClient . hydrateRoot ( container , < App /> ) ;
@@ -278,8 +295,10 @@ describe('ReactDOMFizzForm', () => {
278
295
) ;
279
296
}
280
297
281
- const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
282
- await readIntoContainer ( stream ) ;
298
+ await serverAct ( async ( ) => {
299
+ const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
300
+ await readIntoContainer ( stream ) ;
301
+ } ) ;
283
302
let root ;
284
303
await act ( async ( ) => {
285
304
root = ReactDOMClient . hydrateRoot ( container , < App /> ) ;
@@ -333,13 +352,15 @@ describe('ReactDOMFizzForm', () => {
333
352
334
353
// Specifying the extra form fields are a DEV error, but we expect it
335
354
// to eventually still be patched up after an update.
336
- await expect ( async ( ) => {
337
- const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
338
- await readIntoContainer ( stream ) ;
339
- } ) . toErrorDev ( [
340
- 'Cannot specify a encType or method for a form that specifies a function as the action.' ,
341
- 'Cannot specify a formTarget for a button that specifies a function as a formAction.' ,
342
- ] ) ;
355
+ await serverAct ( async ( ) => {
356
+ await expect ( async ( ) => {
357
+ const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
358
+ await readIntoContainer ( stream ) ;
359
+ } ) . toErrorDev ( [
360
+ 'Cannot specify a encType or method for a form that specifies a function as the action.' ,
361
+ 'Cannot specify a formTarget for a button that specifies a function as a formAction.' ,
362
+ ] ) ;
363
+ } ) ;
343
364
let root ;
344
365
await expect ( async ( ) => {
345
366
await act ( async ( ) => {
@@ -379,8 +400,10 @@ describe('ReactDOMFizzForm', () => {
379
400
return 'Pending: ' + pending ;
380
401
}
381
402
382
- const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
383
- await readIntoContainer ( stream ) ;
403
+ await serverAct ( async ( ) => {
404
+ const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
405
+ await readIntoContainer ( stream ) ;
406
+ } ) ;
384
407
expect ( container . textContent ) . toBe ( 'Pending: false' ) ;
385
408
386
409
await act ( ( ) => ReactDOMClient . hydrateRoot ( container , < App /> ) ) ;
@@ -400,8 +423,10 @@ describe('ReactDOMFizzForm', () => {
400
423
) ;
401
424
}
402
425
403
- const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
404
- await readIntoContainer ( stream ) ;
426
+ await serverAct ( async ( ) => {
427
+ const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
428
+ await readIntoContainer ( stream ) ;
429
+ } ) ;
405
430
406
431
// Dispatch an event before hydration
407
432
submit ( container . getElementsByTagName ( 'form' ) [ 0 ] ) ;
@@ -441,8 +466,10 @@ describe('ReactDOMFizzForm', () => {
441
466
) ;
442
467
}
443
468
444
- const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
445
- await readIntoContainer ( stream ) ;
469
+ await serverAct ( async ( ) => {
470
+ const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
471
+ await readIntoContainer ( stream ) ;
472
+ } ) ;
446
473
447
474
submit ( container . getElementsByTagName ( 'input' ) [ 1 ] ) ;
448
475
submit ( container . getElementsByTagName ( 'button' ) [ 0 ] ) ;
@@ -463,8 +490,10 @@ describe('ReactDOMFizzForm', () => {
463
490
return optimisticState ;
464
491
}
465
492
466
- const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
467
- await readIntoContainer ( stream ) ;
493
+ await serverAct ( async ( ) => {
494
+ const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
495
+ await readIntoContainer ( stream ) ;
496
+ } ) ;
468
497
expect ( container . textContent ) . toBe ( 'hi' ) ;
469
498
470
499
await act ( async ( ) => {
@@ -484,8 +513,10 @@ describe('ReactDOMFizzForm', () => {
484
513
return state ;
485
514
}
486
515
487
- const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
488
- await readIntoContainer ( stream ) ;
516
+ await serverAct ( async ( ) => {
517
+ const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
518
+ await readIntoContainer ( stream ) ;
519
+ } ) ;
489
520
expect ( container . textContent ) . toBe ( '0' ) ;
490
521
491
522
await act ( async ( ) => {
@@ -521,8 +552,10 @@ describe('ReactDOMFizzForm', () => {
521
552
) ;
522
553
}
523
554
524
- const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
525
- await readIntoContainer ( stream ) ;
555
+ await serverAct ( async ( ) => {
556
+ const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
557
+ await readIntoContainer ( stream ) ;
558
+ } ) ;
526
559
527
560
const form = container . firstChild ;
528
561
expect ( form . getAttribute ( 'action' ) ) . toBe ( 'action' ) ;
@@ -581,8 +614,10 @@ describe('ReactDOMFizzForm', () => {
581
614
) ;
582
615
}
583
616
584
- const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
585
- await readIntoContainer ( stream ) ;
617
+ await serverAct ( async ( ) => {
618
+ const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
619
+ await readIntoContainer ( stream ) ;
620
+ } ) ;
586
621
587
622
const input = container . getElementsByTagName ( 'input' ) [ 1 ] ;
588
623
const button = container . getElementsByTagName ( 'button' ) [ 0 ] ;
@@ -651,8 +686,10 @@ describe('ReactDOMFizzForm', () => {
651
686
) ;
652
687
}
653
688
654
- const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
655
- await readIntoContainer ( stream ) ;
689
+ await serverAct ( async ( ) => {
690
+ const stream = await ReactDOMServer . renderToReadableStream ( < App /> ) ;
691
+ await readIntoContainer ( stream ) ;
692
+ } ) ;
656
693
657
694
const barField = container . querySelector ( '[name=bar]' ) ;
658
695
0 commit comments