Skip to content

fix: keep sidebar file changes live while window is visible#1341

Merged
rabanspiegel merged 2 commits intomainfrom
emdash/chore-12ci10rgbf9f9fafafbfb11rgb00000000000010rgbf9f9fafafbfb11r-2xl
Mar 6, 2026
Merged

fix: keep sidebar file changes live while window is visible#1341
rabanspiegel merged 2 commits intomainfrom
emdash/chore-12ci10rgbf9f9fafafbfb11rgb00000000000010rgbf9f9fafafbfb11r-2xl

Conversation

@rabanspiegel
Copy link
Contributor

@rabanspiegel rabanspiegel commented Mar 6, 2026

Summary

  • keep file change refreshes active while the app window is visible, even if it is not focused
  • continue pausing refreshes when the document is hidden so this does not turn into background polling
  • add a small renderer test covering the refresh gating logic

Testing

  • pnpm run format
  • pnpm run lint
  • pnpm run type-check
  • pnpm exec vitest run

Note

Low Risk
Adjusts file-change polling gating logic, which could slightly increase refresh activity when the window is visible but unfocused; behavior remains paused when the document is hidden.

Overview
Keeps sidebar file-change refreshes running whenever a task is active and the document is visible, removing the prior requirement that the window be focused.

Extracts the polling gate into shouldRefreshFileChanges (and adds a small Vitest unit test for it), and tightens typing around requestIdleCallback/cancelIdleCallback usage in useFileChanges.

Written by Cursor Bugbot for commit b7abd4d. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Mar 6, 2026

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

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Mar 6, 2026 9:56pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 6, 2026

Greptile Summary

This PR widens the condition under which the sidebar polls for file changes: previously refreshes were gated on the window having keyboard focus (document.hasFocus() / focus/blur events); now they fire whenever the document is visible (i.e. the tab/window is not hidden), matching the stated intent of keeping the sidebar live while the app is on-screen even if another window has focus.

Key changes:

  • isWindowFocused state and its focus/blur event listeners are removed from useFileChanges
  • The polling predicate is extracted into an exportable shouldRefreshFileChanges(taskPath, isActive, isDocumentVisible) pure function, making the gate easy to unit-test independently
  • (window as any) casts for requestIdleCallback/cancelIdleCallback are replaced with a proper IdleCallbackWindow intersection type
  • A new Vitest file exercises the three negative cases and the positive case for the helper, though one test case is an exact duplicate of another (same inputs, same expectation, but a different description that implies focus-related coverage)

Confidence Score: 5/5

  • This PR is safe to merge; the behavioural change is intentional and well-scoped.
  • The change is small and surgical — one state variable and two event listeners removed, logic extracted into a pure function, and any casts eliminated. The core polling logic and all downstream effects are unchanged. The only issue is a duplicate/misleading test case which does not affect correctness.
  • No files require special attention beyond the minor duplicate test case in src/test/renderer/useFileChanges.test.ts.

Important Files Changed

Filename Overview
src/renderer/hooks/useFileChanges.ts Removes the isWindowFocused state and its focus/blur event listeners; replaces the inline shouldPoll expression with an exported shouldRefreshFileChanges helper; replaces (window as any) casts with a properly-typed IdleCallbackWindow intersection type. Logic is clean and correct.
src/test/renderer/useFileChanges.test.ts New unit tests for shouldRefreshFileChanges; covers the main gate conditions (missing path, inactive, hidden document) but contains a duplicate test case whose description misleadingly implies focus-related coverage.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[shouldRefreshFileChanges called] --> B{taskPath defined?}
    B -- No --> Z[return false — no polling]
    B -- Yes --> C{isActive?}
    C -- No --> Z
    C -- Yes --> D{isDocumentVisible?}
    D -- No --> Z
    D -- Yes --> E[return true — poll / refresh]

    subgraph Before PR
        F[also required isWindowFocused via focus/blur events]
    end

    subgraph After PR
        G[window focus no longer gated — document visibility is sufficient]
    end

    E -.->|was also blocked by| F
    E -.->|now uses| G
Loading

Last reviewed commit: 838668e

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@rabanspiegel rabanspiegel merged commit d62d965 into main Mar 6, 2026
5 checks passed
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.

1 participant