Skip to content

fix: pause leaderboard polling when tab is hidden using Page Visibili…#183

Merged
jagdish-15 merged 2 commits into
codepvg:mainfrom
5hivam123:fix/leaderboard-visibility-polling
Jun 15, 2026
Merged

fix: pause leaderboard polling when tab is hidden using Page Visibili…#183
jagdish-15 merged 2 commits into
codepvg:mainfrom
5hivam123:fix/leaderboard-visibility-polling

Conversation

@5hivam123

Copy link
Copy Markdown
Contributor

Description

Replaced the always-running setInterval with a Page Visibility API implementation that pauses polling when the browser tab is hidden and resumes immediately when the user switches back to the tab — saving unnecessary bandwidth and API calls.

Linked Issue

Fixes #172

Changes Made

  • Removed direct setInterval(fetchLeaderboardData, 2 * 60 * 1000) call
  • Added startPolling() and stopPolling() helper functions
  • Added visibilitychange event listener to pause/resume polling based on tab visibility
  • On tab becoming visible, triggers an immediate fetch before resuming interval

Type of Change

  • Bug fix
  • New feature
  • UI/Visual update
  • Documentation update
  • Refactor

Testing

  • Tested locally
  • Tested on mobile viewport (if applicable)
  • No console errors introduced

Checklist

  • My code follows the project's coding style
  • I have formatted my code locally by running npx prettier --write . before submitting
  • I am submitting my PR from a dedicated feature/* branch, not the main branch
  • I have performed a self-review of my code
  • My changes generate no new warnings or errors
  • I have updated documentation if required
  • I have linked the relevant issue

Screenshots / Screen Recording

Before: Network requests fired every 2 minutes regardless of tab visibility.

After: Network requests pause when tab is hidden, resume immediately on tab focus.

Tested via DevTools → Network tab by switching browser tabs and confirming no fetch calls during hidden state.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for submitting a pull request.

Please ensure your changes comply with the project's contribution guidelines and that all workflow checks pass successfully.

Formatting and Branching

  • Please confirm you have formatted your code locally using npx prettier --write ., or you can simply comment /format on this PR to have our bot do it for you!
  • Ensure this PR is made from a feature/* branch and not main.

Note: This project is currently maintained by a solo maintainer, so reviews and responses may sometimes take a little time. Thanks for your patience.

@jagdish-15

Copy link
Copy Markdown
Collaborator

/format

@github-actions

Copy link
Copy Markdown
Contributor

I have successfully run Prettier and pushed the formatting fixes to this PR.

Note for Contributors: Because this commit was pushed by a bot, GitHub will not automatically re-run the CI checks. To trigger them to pass, you must either:

  • Push an empty commit locally (git commit --allow-empty -m "Trigger builds" and push)
  • Close and immediately reopen this Pull Request.

@jagdish-15 jagdish-15 merged commit 692e582 into codepvg:main Jun 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance]: Leaderboard polls every 2 minutes even when browser tab is hidden

2 participants