Skip to content

fix(applications): prevent duplicate application submissions with in-flight coalescing and button locking - #96

Merged
SagiEv merged 5 commits into
mainfrom
bugfix/general
Nov 6, 2026
Merged

SagiEv merged 5 commits into
mainfrom
bugfix/general

Conversation

@SagiEv

@SagiEv SagiEv commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Description

Resolves an issue where rapid or repeated submit clicks when creating a new job application resulted in multiple duplicate records with distinct IDs in the database.

This fix addresses both the frontend UI interaction layer and backend execution boundaries by implementing synchronous button locking, in-flight request coalescing, and database duplicate detection with idempotent 200 OK responses.


Changes

🎨 Tier 1: Frontend (React)

  • Button Lock & State (ApplicationsPage.jsx):
    • Bound submit button text to {isAdding ? 'Adding...' : 'Save Application'} and marked disabled={isAdding || !newAppForm.COMPANY || !newAppForm.ROLE_ID}.
    • Disabled the modal cancel button, backdrop dismissal, and close button while submission is in-flight.
    • Added an early return guard in onSubmit (if (isAdding) return;).
    • Reset STAGE: '' alongside all form fields upon successful creation.
  • Synchronous Click Guard (useApplications.js):
    • Added an isAddingRef = useRef(false) lock inside addApplication to intercept rapid synchronous clicks within the same event loop tick before React re-renders.
    • Exposed isAdding: addApplicationMutation.isPending.

⚙️ Tier 2: Primary Backend (Node.js / Express)

  • In-Flight Request Coalescing (applications.controller.js):
    • Maintained an in-flight cache keyed by normalized ${userId}:${company}:${roleId}:${date}.
    • Concurrent incoming requests coalesce onto the single active promise, avoiding redundant synchronous fit-context calculations and duplicate asynchronous background AI jobs.
  • Service Deduplication (applications.service.js):
    • Implemented in-flight coalescing (inFlightCreations) and normalized application dates to the calendar day (YYYY-MM-DD, ignoring hours/time components).
    • Queried repository duplicate lookup before inserting. If a matching record already exists for the user on that date, returns the existing application idempotently with 200 OK (tagged _wasDeduplicated: true) without creating orphan history entries.

@vercel

vercel Bot commented Nov 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
job-pilot Ready Ready Preview Nov 5, 2026 11:05pm UTC

@SagiEv
SagiEv merged commit 32e59cf into main Nov 6, 2026
9 of 10 checks passed

This branch was successfully deployed

1 active deployment
Preview — 38cda1d4 Deployed Nov 5, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant