Add test for multiple form submissions (#33059)
Test for #30041 and #33055
Matt Carroll committed
May 5, 2025 at 14:47 UTC
79586c7eb626c6b9362c308a54c9ee5b66e640e5
1 file changed
+31
packages/react-dom/src/__tests__/ReactDOMForm-test.js
+31
@@ -1670,6 +1670,37 @@ describe('ReactDOMForm', () => {
1670
expect(divRef.current.textContent).toEqual('Current username: acdlite');
1671
});
1672
1673
+ it('parallel form submissions do not throw', async () => {
1674
+ const formRef = React.createRef();
1675
+ let resolve = null;
1676
+ function App() {
1677
+ async function submitForm() {
1678
+ Scheduler.log('Action');
1679
+ if (!resolve) {
1680
+ await new Promise(res => {
1681
+ resolve = res;
1682
+ });
1683
+ }
1684
+ }
1685
+ return <form ref={formRef} action={submitForm} />;
1686
+ }
1687
+ const root = ReactDOMClient.createRoot(container);
1688
+ await act(() => root.render(<App />));
1689
+
1690
+ // Start first form submission
1691
+ await act(async () => {
1692
+ formRef.current.requestSubmit();
1693
+ });
1694
+ assertLog(['Action']);
1695
+
1696
+ // Submit form again while first form action is still pending
1697
+ await act(async () => {
1698
+ formRef.current.requestSubmit();
1699
+ resolve(); // Resolve the promise to allow the first form action to complete
1700
+ });
1701
+ assertLog(['Action']);
1702
+ });
1703
+
1704
it(
1705
'requestFormReset works with inputs that are not descendants ' +
1706
'of the form element',