Performance: Concurrent submissions handling
This concept affects how quickly the page responds to multiple form submissions and prevents slowdowns or UI freezes during concurrent user actions.
export async function action({ request }) { const formData = await request.formData(); processSubmission(formData); // fire and forget async return redirect('/success'); } // In the component <form method="post" preventScrollReset> <button type="submit" disabled={isSubmitting}>Submit</button> </form> // Use useTransition hook to track submission state and disable button
export async function action({ request }) { const formData = await request.formData(); await processSubmission(formData); // long-running synchronous task return redirect('/success'); } // In the component <form method="post"> <button type="submit">Submit</button> </form>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous await on submission | Minimal | 1 reflow per submission | Medium paint due to UI freeze | [X] Bad |
| Asynchronous fire-and-forget with disabled button | Minimal | 1 reflow for button disable | Low paint cost, smooth UI | [OK] Good |
isSubmitting to disable the button only during submission.disabled={isSubmitting} disables the button dynamically, unlike hardcoded true or false.export const action = async ({ request }) => {
const formData = await request.formData();
const email = formData.get('email');
if (await isEmailRegistered(email)) {
return json({ error: 'Email already registered' }, { status: 400 });
}
await registerEmail(email);
return json({ success: true });
};function MyForm() {
const transition = useTransition();
return (
<form method="post">
<button disabled={transition.state === 'submitting'}>Send</button>
</form>
);
}Users report the button sometimes stays disabled forever after submission. What is the likely cause?transition.state is 'submitting' while waiting for server response, then changes to 'idle' when done.transition.state stays 'submitting', keeping the button disabled forever.Pass the test and this pattern moves unknown