Skip to content

fix(leaderboard): add request sequencing and unmount guard to prevent race conditions (closes #79) - #333

Open
ghzhost wants to merge 1 commit into
SmartDropLabs:mainfrom
ghzhost:fix/leaderboard-race-condition-79
Open

fix(leaderboard): add request sequencing and unmount guard to prevent race conditions (closes #79)#333
ghzhost wants to merge 1 commit into
SmartDropLabs:mainfrom
ghzhost:fix/leaderboard-race-condition-79

Conversation

@ghzhost

@ghzhost ghzhost commented Sep 5, 2026

Copy link
Copy Markdown

Summary

Fixes a race condition in useLeaderboard where rapid pagination/sorting changes or overlapping 30s auto-refresh cycles could cause out-of-order responses to overwrite the leaderboard state with stale data.

Changes

  • Request sequencing: Added requestIdRef counter incremented on each refresh() invocation. Responses matching superseded request IDs are discarded before updating entries, total, lastRefreshed, or isLoading.
  • Unmount protection: Added isMountedRef lifecycle tracking so in-flight promises resolving after unmount safely drop state updates without emitting warnings.
  • Unit & regression tests: Enhanced useLeaderboard.test.ts to test out-of-order resolution, stale response discarding, auto-refresh interleaving, and unmount safety.

Closes #79

@netlify

netlify Bot commented Sep 5, 2026

Copy link
Copy Markdown

Deploy Preview for spiffy-melomakarona-eb1e8a ready!

Name Link
🔨 Latest commit 62ac3b5
🔍 Latest deploy log https://app.netlify.com/projects/spiffy-melomakarona-eb1e8a/deploys/6a9b8c51420c5b0008970542
😎 Deploy Preview https://deploy-preview-333--spiffy-melomakarona-eb1e8a.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Sep 5, 2026

Copy link
Copy Markdown

Deploy Preview for smart-drop ready!

Name Link
🔨 Latest commit 62ac3b5
🔍 Latest deploy log https://app.netlify.com/projects/smart-drop/deploys/6a9b8c513c53f70008ca165b
😎 Deploy Preview https://deploy-preview-333--smart-drop.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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.

useLeaderboard has no race-condition guard — rapid sort/page changes can let a stale response overwrite a newer one

1 participant