Skip to content

fix(marketplace): guard realtime bid updates against stale and duplicate deliveries#300

Merged
MaryammAli merged 2 commits into
BlockDash-Studios:mainfrom
Alanwiz00:fix/marketplace-bid-race-conditions
Jul 17, 2026
Merged

fix(marketplace): guard realtime bid updates against stale and duplicate deliveries#300
MaryammAli merged 2 commits into
BlockDash-Studios:mainfrom
Alanwiz00:fix/marketplace-bid-race-conditions

Conversation

@Alanwiz00

Copy link
Copy Markdown
Contributor

Fixes #292

Summary

This PR fixes inconsistencies in the marketplace's realtime bid updates caused by duplicate, stale, and out-of-order websocket events. It also stabilizes realtime subscriptions and ensures marketplace views stay synchronized with the latest listing state.

Problem

The marketplace updated bidCount by incrementing it for every websocket event, while currentBid was derived using Math.max(). As a result:

  • Duplicate or stale websocket events could inflate the bid count.
  • A user's own bid could be counted twice when the websocket echo arrived.
  • Subscription effects recreated listeners unnecessarily, creating windows where updates could be missed.
  • Open modals displayed stale listing data instead of reflecting live updates.

Changes

  • Introduced a shared bid update utility that applies only monotonic bid updates, ignoring stale, duplicate, and out-of-order events.
  • Updated local bid handling to use the same logic, preventing websocket echoes from being applied twice.
  • Stabilized realtime subscriptions by tracking listing IDs instead of the entire listings array.
  • Updated marketplace modals to derive their data from the latest application state rather than stale snapshots.
  • Improved the mock realtime feed to emit monotonic bid updates while intentionally replaying some stale events to validate the update logic.
  • Added unit test infrastructure and comprehensive test coverage for duplicate events, out-of-order delivery, websocket echo deduplication, and bid regression scenarios.
  • Fixed a few unrelated build issues uncovered during testing, including existing rename inconsistencies and a card-number redaction ordering issue.

Testing

  • ✅ All unit tests pass.

  • ✅ Type checking passes.

  • ✅ ESLint passes.

  • ✅ Verified manually that:

    • bid counts increase only for genuine new bids;
    • duplicate and stale websocket events are ignored;
    • local bids are not double-counted when echoed back;
    • open listing detail views stay synchronized with live updates.

@MaryammAli MaryammAli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MaryammAli

Copy link
Copy Markdown
Contributor

you have conflict
@Alanwiz00

@Alanwiz00

Copy link
Copy Markdown
Contributor Author

conflict resolved ✅

@MaryammAli MaryammAli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MaryammAli
MaryammAli merged commit b66cd89 into BlockDash-Studios:main Jul 17, 2026
1 check passed
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.

marketplace real-time update handler can produce stale state and duplicate bid count increments

2 participants