From 79586c7eb626c6b9362c308a54c9ee5b66e640e5 Mon Sep 17 00:00:00 2001 From: Matt Carroll <7158882+mattcarrollcode@users.noreply.github.com> Date: Mon, 5 May 2025 14:47:47 -0700 Subject: [PATCH] Add test for multiple form submissions (#33059) Test for #30041 and #33055 --- .../src/__tests__/ReactDOMForm-test.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/packages/react-dom/src/__tests__/ReactDOMForm-test.js b/packages/react-dom/src/__tests__/ReactDOMForm-test.js index 93edccf9bcef3..f981ed4c38dcf 100644 --- a/packages/react-dom/src/__tests__/ReactDOMForm-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMForm-test.js @@ -1670,6 +1670,37 @@ describe('ReactDOMForm', () => { expect(divRef.current.textContent).toEqual('Current username: acdlite'); }); + it('parallel form submissions do not throw', async () => { + const formRef = React.createRef(); + let resolve = null; + function App() { + async function submitForm() { + Scheduler.log('Action'); + if (!resolve) { + await new Promise(res => { + resolve = res; + }); + } + } + return
; + } + const root = ReactDOMClient.createRoot(container); + await act(() => root.render()); + + // Start first form submission + await act(async () => { + formRef.current.requestSubmit(); + }); + assertLog(['Action']); + + // Submit form again while first form action is still pending + await act(async () => { + formRef.current.requestSubmit(); + resolve(); // Resolve the promise to allow the first form action to complete + }); + assertLog(['Action']); + }); + it( 'requestFormReset works with inputs that are not descendants ' + 'of the form element',