Skip to content

perf(git): pause git status polling when page is hidden#600

Open
HUQIANTAO wants to merge 1 commit into
op7418:mainfrom
HUQIANTAO:perf/git-status-polling
Open

perf(git): pause git status polling when page is hidden#600
HUQIANTAO wants to merge 1 commit into
op7418:mainfrom
HUQIANTAO:perf/git-status-polling

Conversation

@HUQIANTAO
Copy link
Copy Markdown

Problem

useGitStatus polls GET /api/git/status every 10 seconds via setInterval, unconditionally. Each poll spawns a git status subprocess on the server side — in large repos this takes 200–500ms. The polling continues even when:

  • The page is hidden (user switched to another tab)
  • The window is minimized
  • The user is on the settings page where git status isn't displayed

Combined with the notification poll (5s interval), the app makes at least 1 HTTP request every 5 seconds even when completely idle.

Fix

Implement visibility-aware pause/resume:

  • Page hidden → stop the setInterval entirely. No polls, no HTTP requests, no subprocess spawns.
  • Page visible → fetch immediately (to catch any changes that happened while hidden) and restart the interval.
  • Manual refresh → the git-refresh custom event listener remains active regardless of visibility state.

This eliminates all background git polling when the app isn't being actively viewed, reducing both CPU (no subprocess spawns) and network overhead.

useGitStatus polls GET /api/git/status every 10s via setInterval,
regardless of page visibility. Each poll spawns a git subprocess on
the server side — in large repos this takes 200-500ms. Combined with
the notification poll (5s), the app makes at least 1 HTTP request
every 5 seconds even when the user is on a different tab or the
window is minimized.

Fix: stop the interval when document.visibilityState === 'hidden'
and restart it (with an immediate fetch) when the page becomes
visible again. The git-refresh custom event listener remains active
so manual refreshes still work regardless of visibility state.
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 4, 2026

Someone is attempting to deploy a commit to the op7418's projects Team on Vercel.

A member of the Team first needs to authorize it.

@HUQIANTAO HUQIANTAO changed the base branch from worktree-product-refactor-research to main June 5, 2026 05:29
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.

1 participant