Skip to content

Refetch polling queries on window focus - #3480

Open
david-crespo wants to merge 2 commits into
mainfrom
refetch-on-focus
Open

david-crespo wants to merge 2 commits into
mainfrom
refetch-on-focus

Conversation

@david-crespo

@david-crespo david-crespo commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Some pages that poll do it pretty slowly in some conditions. For example, on the update page, when nothing has happened in 30 minutes, we slow down to polling every 2 minutes.

const POLL_FAST = 20 * SEC
const POLL_SLOW = 120 * SEC
const statusQuery = q(
api.systemUpdateStatus,
{},
{
refetchInterval({ state: { data: status } }) {
if (!status) return false // should be impossible due to prefetch
const now = new Date()
const minSinceTargetSet = status.targetRelease
? differenceInMinutes(now, status.targetRelease.timeRequested)
: null
const minSinceLastStepPlanned = differenceInMinutes(now, status.timeLastStepPlanned)
return minSinceLastStepPlanned < 30 ||
(minSinceTargetSet !== null && minSinceTargetSet < 30)
? POLL_FAST
: POLL_SLOW
},
}
)

But polling also pauses when the page loses focus. So you might leave the page sitting for an hour, then come back, and you expect it to have polled in that time, but it does not, and unless the poll tick happens to fire in the 10 seconds you are there staring at it, you will not get another poll. It doesn't queue up the next poll to fire when you look or anything. So essentially unless you sit on the page for up to two minutes (which no one would do), it looks broken.

Luckily there is an extremely easy fix: React Query has a refetchOnWindowFocus flag that we have off by default because generally we try to keep the site behaving like a traditional server-rendered app, but on pages that poll (instances, support bundles, update) that expectation is surely suspended. So we turn it on. I also cut the polling interval from 2 minutes to 1 minute.

@vercel

vercel Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
console Ready Ready Preview Dec 4, 2026 2:58pm UTC

Request Review

@charliepark charliepark 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.

nice!

@david-crespo
david-crespo enabled auto-merge (squash) December 4, 2026 15:10

This branch was successfully deployed

1 active deployment
Preview — accfa7e8 Deployed Dec 4, 2026 by vercel[bot]
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.

2 participants