📌 Description
MetricsBar (src/components/MetricsBar.tsx) auto-refreshes via useInterval (src/hooks/useInterval.ts) per the README's "live metrics bar (auto-refreshing)" description. It keeps polling fetchMetrics (src/lib/metricsApi.ts) even when the browser tab is hidden/backgrounded, wasting requests against the backend's rate-limited API for a view nobody is looking at.
🧩 Requirements and context
- Pause the interval when
document.visibilityState === "hidden" and resume it (with an immediate refresh) when the tab becomes visible again.
- No change to
useInterval's generic public API — implement the visibility gating in MetricsBar or as an opt-in enhancement to the hook.
- Preserve existing cleanup-on-unmount behavior.
🛠️ Suggested execution
- Add a
visibilitychange listener in MetricsBar.tsx (or useInterval.ts) that stops/restarts the interval accordingly.
- Extend
src/hooks/useInterval.test.ts and/or src/components/MetricsBar.test.tsx with a visibility-toggle test using a mocked document.visibilityState.
- Verify no duplicate fetches fire immediately on resume if a fetch was already in flight when the tab was hidden.
✅ Acceptance criteria
🔒 Security notes
No new attack surface; reduces unnecessary load against the rate-limited backend API.
📋 Guidelines
- Minimum 95% test coverage
- Clear documentation
- Timeframe: 96 hours
📌 Description
MetricsBar(src/components/MetricsBar.tsx) auto-refreshes viauseInterval(src/hooks/useInterval.ts) per the README's "live metrics bar (auto-refreshing)" description. It keeps pollingfetchMetrics(src/lib/metricsApi.ts) even when the browser tab is hidden/backgrounded, wasting requests against the backend's rate-limited API for a view nobody is looking at.🧩 Requirements and context
document.visibilityState === "hidden"and resume it (with an immediate refresh) when the tab becomes visible again.useInterval's generic public API — implement the visibility gating inMetricsBaror as an opt-in enhancement to the hook.🛠️ Suggested execution
visibilitychangelistener inMetricsBar.tsx(oruseInterval.ts) that stops/restarts the interval accordingly.src/hooks/useInterval.test.tsand/orsrc/components/MetricsBar.test.tsxwith a visibility-toggle test using a mockeddocument.visibilityState.✅ Acceptance criteria
🔒 Security notes
No new attack surface; reduces unnecessary load against the rate-limited backend API.
📋 Guidelines