@@ -36,6 +36,7 @@ describe('ReactDOMForm', () => {
36
36
let Scheduler ;
37
37
let assertLog ;
38
38
let assertConsoleErrorDev ;
39
+ let waitForMicrotasks ;
39
40
let waitForThrow ;
40
41
let useState ;
41
42
let Suspense ;
@@ -55,6 +56,7 @@ describe('ReactDOMForm', () => {
55
56
Scheduler = require ( 'scheduler' ) ;
56
57
act = require ( 'internal-test-utils' ) . act ;
57
58
assertLog = require ( 'internal-test-utils' ) . assertLog ;
59
+ waitForMicrotasks = require ( 'internal-test-utils' ) . waitForMicrotasks ;
58
60
waitForThrow = require ( 'internal-test-utils' ) . waitForThrow ;
59
61
assertConsoleErrorDev =
60
62
require ( 'internal-test-utils' ) . assertConsoleErrorDev ;
@@ -1671,18 +1673,9 @@ describe('ReactDOMForm', () => {
1671
1673
} ) ;
1672
1674
1673
1675
it ( 'multiple form submissions in rapid succession do not throw' , async ( ) => {
1674
- const submitFormTwiceButtonRef = React . createRef ( ) ;
1676
+ const formRef = React . createRef ( ) ;
1675
1677
let actionCounter = 0 ;
1676
1678
function App ( ) {
1677
- const formRef = React . createRef ( ) ;
1678
- // Submits the form twice in quick succession
1679
- // This simulates a user clicking a button twice in rapid succession
1680
- async function submitFormTwice ( ) {
1681
- formRef . current . requestSubmit ( ) ;
1682
- await new Promise ( res => setTimeout ( res , 1 ) ) ;
1683
- formRef . current . requestSubmit ( ) ;
1684
- }
1685
-
1686
1679
// This is a userspace action. it must take a non-zero amount of time to
1687
1680
// allow the form to be submitted again before the first one finishes.
1688
1681
// Otherwise, the form transitions will be batched and will not run sepereately.
@@ -1696,9 +1689,6 @@ describe('ReactDOMForm', () => {
1696
1689
< form ref = { formRef } action = { submitForm } >
1697
1690
< button type = "submit" > Submit</ button >
1698
1691
</ form >
1699
- < button ref = { submitFormTwiceButtonRef } onClick = { submitFormTwice } >
1700
- Submit twice
1701
- </ button >
1702
1692
</ >
1703
1693
) ;
1704
1694
}
@@ -1707,7 +1697,9 @@ describe('ReactDOMForm', () => {
1707
1697
await act ( ( ) => root . render ( < App /> ) ) ;
1708
1698
1709
1699
await act ( async ( ) => {
1710
- submitFormTwiceButtonRef . current . click ( ) ;
1700
+ formRef . current . requestSubmit ( ) ;
1701
+ await waitForMicrotasks ( ) ;
1702
+ formRef . current . requestSubmit ( ) ;
1711
1703
} ) ;
1712
1704
expect ( actionCounter ) . toBe ( 2 ) ;
1713
1705
} ) ;
0 commit comments