[PR #101] Preventing Double Submission in Customer Registration
I requested this work.
- What was done: On the customer registration screen, pressing the save button again in the short gap right after a save request succeeded, before the screen changed, could send a second save request (POST). The screen code started navigating away after the save succeeded and then returned from the function immediately, and the shared submit helper
useSubmitreleases its submit lock right after that. A new test reproduced the problem by holding the navigation after the first response and pressing again. A “already created” flag (createdRef, a memory slot that lives only inside the screen) was added to this one screen (CustomerCreatePage). When the save request succeeds, the flag is set before navigating or issuing an invitation code, and if the screen is submitted again while the flag is set, it returns immediately and does nothing. - Chosen approach: The shared helper
useSubmitwas not changed, and only this one screen was fixed. If the save request fails, the flag is not set, so the user can save again after fixing the error. - Checks:
- Before the fix, the new test failed and recorded 2 request bodies. After the fix, it passed.
- The customer registration test file (
create.test.tsx) was run 30 times in a row and passed every time. - The shared package build, the admin type check and the lint all passed.
- Only 2 admin web files changed (5 lines of screen code, 43 lines of tests) plus documents. The server,
useSubmit, other screens, packages and settings are unchanged.
| Item | Content |
|---|---|
| Problem | Pressing again right after a save succeeded, before the screen changed, could send the save request twice |
| Where it was fixed | One customer registration screen (the shared useSubmit is unchanged) |
| When it fails | The flag is not set, so the user can save again after fixing the error |
| Checks | Test failed before the fix (2 requests), passed after, 30 passes in a row, type check and lint passed |
Who did what
- Me: Requested the work.
- Fizz (GPT-6 Luna): Implemented the guard that prevents double submission.
- Pollen (OpenCode free model glm-5.3-flash-free): Reviewed and approved. It judged that both retrying after an error and a quick double click are blocked or allowed correctly.
- Claude (PL, Sonnet 5.5): Checked the scope of the change and organized the review result. Because Fizz implemented it, Fizz was not asked to review (no self-review).
- Cloud session (Claude Sonnet 5.5): The work log says it was used in this work, but it does not say what it did. This could not be confirmed.
What was chosen and what was left
- Chosen: The fix was made only in the one screen where the problem occurred, and the shared helper was left as it was.
- Left: Pollen pointed out one low-risk item. There is no test that checks only the “register, then issue an invitation code” button. That button uses the same guard, so it was not changed.
What could not be checked
- The work log has no record of a person pressing twice quickly in a real browser. The checks above are automated test and static check results.
Lessons
There is a gap between the moment a submit function finishes and the moment the screen actually changes. Check whether the shared lock covers that gap, and if it does not, block it separately in the screen after the request has succeeded.