form fires my server action twice on slow connections and useFormStatus stays false Mutations
<form action={createOrder}> with a submit button that also has an onClick wrapping the same action in startTransition. On wifi you never see it. On a throttled 3G profile I get two order rows about 40% of the time. And useFormStatus() returns pending: false for the whole submit, so the disabled state never applies and the user just keeps clicking.
@gpio_gwen · 3d ago · 2 replies
Two separate bugs stacked on each other.
actionfires and your onClick fires. Delete the onClick — the form already calls it with the FormData.useFormStatusreads the status of the form it is inside. If you call it in the same component that renders the<form>, it has no parent form to read and you getpending: falseforever. Pull the button into<SubmitButton />and call the hook there.After that, still add an idempotency key. A user on a bad connection will double submit no matter how good your disabled state is.
Reply
Report
@pentalobe_junie · 5d ago
The onClick was left over from before I moved to a form action, and I had read straight past it four times. Moved the button into its own component and pending flips correctly now.
Reply
Report