TechnicalCollectible prompt
Fix a form that submits twice or saves duplicates
Act as a senior full-stack engineer. In my {{tech_stack}} app, the form on {{page_or_feature}} sometimes submits twice: duplicate rows, two emails or two charges. Steps: {{steps_to_reproduce}}
Gather evidence first:
- In the network tab, are there two requests? Note the gap: milliseconds apart suggests a double handler or double click; seconds apart suggests a retry or an impatient user
- Server logs and the duplicate database rows, with timestamps
- Whether it happens only in development, where Strict Mode runs effects twice, or in production too
Likely causes, ranked for this symptom:
1. Nothing stops a second click while the first request is in flight, especially on slow phones
2. Two handlers: an onClick on the button plus an onSubmit on the form, or a listener added on every render
3. The submit triggered from an effect that runs again
4. Pressing Enter in a field and clicking the button
5. A network retry, or the user going back and resubmitting, with no protection on the server
6. A webhook or background job that also creates the record
Fix it at two levels:
- Browser: one submit handler on the form; disable the button and show a loading label while pending; re-enable it on error with a clear message
- Server, the real guard, since the browser can't be trusted: an idempotency key per submission, or a unique constraint on the natural key (such as user plus booking slot) that returns the existing record instead of failing. For payments, pass an idempotency key to the payment provider
Add a test that fires two submits in quick succession and asserts one record. Explain the cause in plain words, and how to clean up existing duplicates safely.
Technicalnvoka.com/library/nvoka-fix-a-form-that-submits-twice-or-saves-duplicatesScan to open
Technical
Fix a form that submits twice or saves duplicates
Find why one click creates two records or two charges, then fix it in the browser and on the server.
Curated by Nvoka
CursorClaude CodeCodexLovable
Make it yours
Fill in the blanks and change any word. Only your copy changes, never the card.
Fill in the blanks
0 of 3 filledYour prompt
Act as a senior full-stack engineer. In my {{tech_stack}} app, the form on {{page_or_feature}} sometimes submits twice: duplicate rows, two emails or two charges. Steps: {{steps_to_reproduce}}
Gather evidence first:
- In the network tab, are there two requests? Note the gap: milliseconds apart suggests a double handler or double click; seconds apart suggests a retry or an impatient user
- Server logs and the duplicate database rows, with timestamps
- Whether it happens only in development, where Strict Mode runs effects twice, or in production too
Likely causes, ranked for this symptom:
1. Nothing stops a second click while the first request is in flight, especially on slow phones
2. Two handlers: an onClick on the button plus an onSubmit on the form, or a listener added on every render
3. The submit triggered from an effect that runs again
4. Pressing Enter in a field and clicking the button
5. A network retry, or the user going back and resubmitting, with no protection on the server
6. A webhook or background job that also creates the record
Fix it at two levels:
- Browser: one submit handler on the form; disable the button and show a loading label while pending; re-enable it on error with a clear message
- Server, the real guard, since the browser can't be trusted: an idempotency key per submission, or a unique constraint on the natural key (such as user plus booking slot) that returns the existing record instead of failing. For payments, pass an idempotency key to the payment provider
Add a test that fires two submits in quick succession and asserts one record. Explain the cause in plain words, and how to clean up existing duplicates safely.
