Skip to content

Fix optimistic-rollback race in src/shared/hooks/useOptimisticData.ts #458

Description

@Jagadeeshftw

📌 Description

src/shared/hooks/useOptimisticData.ts applies an optimistic update then rolls back on failure. If two optimistic updates are in flight concurrently (e.g. rapid double-submit) and the first fails while the second is still pending, the rollback may incorrectly revert the second (still-pending) update's optimistic state instead of only its own.

🧩 Requirements and context

  • Scope each optimistic update's rollback to only the state it changed, not a blanket revert-to-previous-snapshot.
  • Handle overlapping in-flight updates correctly (e.g. via per-update tokens/versioning).
  • Add a regression test simulating two overlapping updates where the first fails and the second succeeds.

🛠️ Suggested execution

  • Review the rollback logic in useOptimisticData.ts for a shared 'previous snapshot' that multiple in-flight updates could clobber.
  • Introduce per-update tracking (e.g. a version counter) so rollback only affects its own change.
  • Add the overlapping-updates regression test.

✅ Acceptance criteria

  • A failed optimistic update only rolls back its own change, not a concurrently-succeeding one.
  • Regression test explicitly covers the overlapping-update race.
  • Existing single-update optimistic/rollback tests still pass.

🔒 Security notes

No security impact; this is a data-correctness bug.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial Campaign | FWC26GrantFox official campaign issuefrontendFrontend / UI work

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions