Skip to content

Commit 79586c7

Browse files
Add test for multiple form submissions (facebook#33059)
Test for facebook#30041 and facebook#33055
1 parent edf550b commit 79586c7

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

packages/react-dom/src/__tests__/ReactDOMForm-test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,37 @@ describe('ReactDOMForm', () => {
16701670
expect(divRef.current.textContent).toEqual('Current username: acdlite');
16711671
});
16721672

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+
16731704
it(
16741705
'requestFormReset works with inputs that are not descendants ' +
16751706
'of the form element',

0 commit comments

Comments
 (0)