perf(frontend): integrate page visibility API for smart polling#604
perf(frontend): integrate page visibility API for smart polling#604wahh3b-lgtm wants to merge 2 commits into
Conversation
- Add useDocumentVisibility hook using Page Visibility API - Dashboard polling: reduce from 5s to 60s when tab is hidden - Chart polling: reduce from 5min to 15min when visible, 1hr when hidden - Workers health: combine pauseRefetch with visibility-aware polling - Version check: disable periodic polling (on-demand only) - Router: fix TypeScript type safety (satisfies RouteObject[])
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR implements visibility-aware polling optimization across the dashboard by introducing a ChangesTab Visibility-Aware Polling
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@dashboard/src/components/charts/user-sub-update-pie-chart.tsx`:
- Around line 175-176: The refetchInterval currently uses 60_000 (60s) when
visible and 1000 * 60 * 5 (5m) when hidden; update these to match the PR
contract by setting refetchInterval to 15 minutes when isTabVisible is true and
1 hour when false (use consistent numeric expressions like 1000 * 60 * 15 and
1000 * 60 * 60) so the polling cadence in the refetchInterval option aligns with
the chart-level target; adjust the line that assigns refetchInterval (the block
using refetchInterval and isTabVisible) accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8697fd87-a58a-4a21-a273-7c122c96cc95
📒 Files selected for processing (12)
.gitignoredashboard/src/app/router.tsxdashboard/src/components/charts/all-nodes-stacked-bar-chart.tsxdashboard/src/components/charts/area-costume-chart.tsxdashboard/src/components/charts/costume-bar-chart.tsxdashboard/src/components/charts/user-sub-update-pie-chart.tsxdashboard/src/features/dashboard/components/admin-statistics-card.tsxdashboard/src/features/dashboard/components/workers-health-card.tsxdashboard/src/features/users/components/users-statistics.tsxdashboard/src/hooks/use-document-visibility.tsdashboard/src/hooks/use-version-check.tsdashboard/src/pages/_dashboard._index.tsx
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Changes
dashboard/src/hooks/use-document-visibility.ts): New React hook using the browser's Page Visibility API to detect when the tab is hidden/minimized_dashboard._index.tsx): System resource and user stats polling reduces from 5s to 60s when the tab is hiddenworkers-health-card.tsx): Combined existingpauseRefetchlogic with visibility-aware pollinguse-version-check.ts): Changed from periodic to on-demand only (reduces unnecessary API calls)router.tsx): Fixedanyreturn type, replacedas RouteObject[]withsatisfies RouteObject[].gitignore): Addedcoderabbitai.mdFiles Changed
dashboard/src/hooks/use-document-visibility.ts(new)dashboard/src/pages/_dashboard._index.tsxdashboard/src/features/users/components/users-statistics.tsxdashboard/src/features/dashboard/components/admin-statistics-card.tsxdashboard/src/features/dashboard/components/workers-health-card.tsxdashboard/src/components/charts/area-costume-chart.tsxdashboard/src/components/charts/costume-bar-chart.tsxdashboard/src/components/charts/user-sub-update-pie-chart.tsxdashboard/src/components/charts/all-nodes-stacked-bar-chart.tsxdashboard/src/hooks/use-version-check.tsdashboard/src/app/router.tsx.gitignoreVerification
Summary by CodeRabbit