Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMForm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('ReactDOMForm', () => {
let Scheduler;
let assertLog;
let assertConsoleErrorDev;
let waitForMicrotasks;
let waitForThrow;
let useState;
let Suspense;
Expand All @@ -55,6 +56,7 @@ describe('ReactDOMForm', () => {
Scheduler = require('scheduler');
act = require('internal-test-utils').act;
assertLog = require('internal-test-utils').assertLog;
waitForMicrotasks = require('internal-test-utils').waitForMicrotasks;
waitForThrow = require('internal-test-utils').waitForThrow;
assertConsoleErrorDev =
require('internal-test-utils').assertConsoleErrorDev;
Expand Down Expand Up @@ -1670,6 +1672,38 @@ describe('ReactDOMForm', () => {
expect(divRef.current.textContent).toEqual('Current username: acdlite');
});

it('multiple form submissions in rapid succession do not throw', async () => {
const formRef = React.createRef();
let actionCounter = 0;
function App() {
// This is a userspace action. it must take a non-zero amount of time to
// allow the form to be submitted again before the first one finishes.
// Otherwise, the form transitions will be batched and will not run sepereately.
async function submitForm() {
actionCounter++;
return new Promise(res => setTimeout(res, 1));
}

return (
<>
<form ref={formRef} action={submitForm}>
<button type="submit">Submit</button>
</form>
</>
);
}

const root = ReactDOMClient.createRoot(container);
await act(() => root.render(<App />));

await act(async () => {
formRef.current.requestSubmit();
await waitForMicrotasks();
formRef.current.requestSubmit();
});
expect(actionCounter).toBe(2);
});

it(
'requestFormReset works with inputs that are not descendants ' +
'of the form element',
Expand Down
Loading