Skip to content

[codex] Pause ticker while panel is hidden#490

Merged
robinebers merged 2 commits into
robinebers:mainfrom
zergzorg:codex/pause-hidden-ticker
May 25, 2026
Merged

[codex] Pause ticker while panel is hidden#490
robinebers merged 2 commits into
robinebers:mainfrom
zergzorg:codex/pause-hidden-ticker

Conversation

@zergzorg
Copy link
Copy Markdown
Contributor

@zergzorg zergzorg commented May 22, 2026

Summary

  • pause useNowTicker intervals while document.hidden is true by default
  • refresh now immediately when the document becomes visible again, before the next interval tick
  • add hook coverage for initially hidden documents, active ticker pause/resume, and opt-out behavior

Why

useNowTicker drives display-only UI such as countdowns and relative timestamps. When the menu panel WebView is hidden, those React timer updates do not change visible UI but can still wake the app. Pausing the ticker while hidden reduces idle UI work without changing provider probes or background refresh scheduling.

This addresses #488 and complements the broader resource-budget discussion in #487.

Notes

The default behavior is visibility-aware, but callers can keep the old hidden ticking behavior with pauseWhenHidden: false if a future use case needs it.

Validation

  • node ./node_modules/vitest/vitest.mjs run src/hooks/use-now-ticker.test.ts
  • bun run build
  • node ./node_modules/vitest/vitest.mjs run

The full Vitest run passes. Existing tests print Tauri store mock stderr in App.test.tsx, but the suite exits successfully.


Summary by cubic

Pause useNowTicker ticks while the document is hidden to reduce idle updates, and resume with an immediate refresh when it becomes visible. Adds a pauseWhenHidden option (default true), respects enabled on visibility changes (no refresh when disabled), and tests for initial hidden state, pause/resume, disabled behavior, and opt‑out.

Written for commit be7d219. Summary will update on new commits. Review in cubic

@github-actions github-actions Bot added the core label May 22, 2026
@zergzorg zergzorg marked this pull request as ready for review May 22, 2026 11:33
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@zergzorg
Copy link
Copy Markdown
Contributor Author

Stack note for maintainers/agents:

This PR is independent from the #487 probe-resource stack. It belongs to #488 and only reduces UI-only ticker work while the panel WebView is hidden.

Suggested merge position: merge anytime. It can land before or after #498/#499/#500 because it does not change probe scheduling, backend probe execution, or provider runtime behavior.

@validatedev
Copy link
Copy Markdown
Collaborator

@codex review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the useNowTicker React hook to be visibility-aware by default, pausing interval updates while document.hidden is true and forcing an immediate refresh when the document becomes visible again. This reduces unnecessary UI timer work when the Tauri panel WebView is hidden, while preserving an opt-out (pauseWhenHidden: false) for callers that need the prior behavior.

Changes:

  • Add pauseWhenHidden option (default true) and a visibilitychange listener to pause/resume ticking based on document visibility.
  • Trigger an immediate now refresh on visibility resume (before the next interval tick).
  • Extend Vitest coverage for initially hidden documents, pause/resume behavior, and opt-out behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/hooks/use-now-ticker.ts Adds visibility-aware pause/resume logic and a new pauseWhenHidden option to reduce hidden-panel interval work.
src/hooks/use-now-ticker.test.ts Adds tests for hidden/visible transitions and opt-out behavior for the visibility-aware ticker.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/hooks/use-now-ticker.ts
Comment thread src/hooks/use-now-ticker.test.ts
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c0614ee81

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/hooks/use-now-ticker.ts Outdated
@zergzorg zergzorg force-pushed the codex/pause-hidden-ticker branch from 2c0614e to be7d219 Compare May 24, 2026 07:03
@zergzorg
Copy link
Copy Markdown
Contributor Author

Addressed the review feedback in the latest push:

  • gated the visibility-resume setNow(Date.now()) behind enabled, so disabled tickers stay stable;
  • restored the original document.hidden descriptor after tests;
  • added a regression test for disabled + visibility resume.

Verified locally with node ./node_modules/vitest/vitest.mjs run src/hooks/use-now-ticker.test.ts using the bundled Node runtime. The updated branch is also rebased on current main, and CI is green.

Copy link
Copy Markdown
Owner

@robinebers robinebers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Display-only ticker change — no impact on app self-update checks (useAppUpdate own setInterval), plugin auto-refresh (useProbeAutoUpdate own setInterval), or tray icon updates (useTrayIcon is probe-result-driven). macOS App Nap is already disabled in app_nap.rs so background timers keep firing while the panel is hidden. Tests are solid, both bot-review nits addressed in commit 2.

@robinebers robinebers merged commit d44008f into robinebers:main May 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants