📌 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
🔒 Security notes
No security impact; this is a data-correctness bug.
📋 Guidelines
- Minimum 95% test coverage
- Clear documentation
- Timeframe: 96 hours
📌 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
🛠️ Suggested execution
useOptimisticData.tsfor a shared 'previous snapshot' that multiple in-flight updates could clobber.✅ Acceptance criteria
🔒 Security notes
No security impact; this is a data-correctness bug.
📋 Guidelines