Repository navigation
perf(web): pause snapshot polling in hidden tabs - #249
Merged
Merged
Conversation
Adds setVisibleInterval (web/src/lib/polling.ts): no ticks while the tab is hidden, an immediate refresh on return, no overlapping polls, errors swallowed, cleanup removes the listener. API pollers use it; local clock ticks keep setInterval. CI runs the helper tests. Backported from #209 (contributed by @renaesop).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backported from #209 (contributed by @renaesop).
Base:
mainat 2ad8ba1.Change
web/src/lib/polling.ts(new):setVisibleInterval(callback, delay), as in Reduce task-tab polling traffic and add online query indexes #209.setTimeoutonly after the previous poll completes.document.visibilityState === "hidden", and there is an immediate refresh when the tab becomes visible again.visibilitychangelistener.web/scripts/polling.test.mjs(new): the three polling tests from Reduce task-tab polling traffic and add online query indexes #209. They transpile the helper with thetypescriptpackage and run it invm, with a fakedocumentand fake timers. The tests cover:web/package.json: adds"test:polling": "node --test scripts/polling.test.mjs".webjob runsnpm run test:pollingafternpx tsc --noEmitand beforenpm run build:static.Adoption
Every poller that calls the API now uses
setVisibleInterval. The initial call stays immediate, and theuseEffectreturns or calls the cleanup.dashboard/page.tsxfunction/findings/page.tsxfunction/tasks/detail/page.tsxfunction/tasks/page.tsx_tabs/sessions-tab.tsx_tabs/graph-tab.tsx,findings-tab.tsx,assets-tab.tsx,overview-tab.tsx,credentials-tab.tsx,broadcast-tab.tsxsystem/llm/page.tsx,_components/sidebar/nav-main.tsx,components/approval-records.tsx,hooks/use-side-questions.ts,function/traffic/page.tsxLocal clock ticks keep
setInterval, because they make no HTTP call:tasks/page.tsx(setNowSec),sessions-tab.tsx(setTick) andbroadcast-tab.tsx(setNow). SSE streams are untouched.The rest of #209 is not included:
inflight.ts, session pagination, the partial graph and the snapshot restructuring. The twoInflightReadstests from #209's test file are therefore left out too.Verification (node v24.19.0, npm 11.19.0)
npm ci: OK.npx tsc --noEmit: OK.npm run test:polling: 3 tests, 3 pass, 0 fail.npm run build:static: OK.