Skip to content

fix: Refresh Review tab diffs on window focus to catch external edits - #197

Merged
Ziinc merged 1 commit into
mainfrom
claude/review-tab-stale-contents-6hwmid
Aug 7, 2026
Merged

fix: Refresh Review tab diffs on window focus to catch external edits#197
Ziinc merged 1 commit into
mainfrom
claude/review-tab-stale-contents-6hwmid

Conversation

@Ziinc

@Ziinc Ziinc commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR adds logic to refresh the Review tab's diff content whenever the application window regains focus. This ensures that file edits made while the window was unfocused are reflected in the UI, even when those edits don't trigger file watcher events (e.g., when editing an already-modified file).

Key Changes

  • useFileLoading hook: Added a window focus listener that re-fetches file changes and hunk content when the window regains focus
    • Uses getCurrentWindow().onFocusChanged() to detect focus events
    • Calls loadChangedFiles() and loadAllFileHunks() to refresh the diff view
    • Gracefully handles non-Tauri environments (like tests) where the window API may not be available
    • Properly cleans up the listener on component unmount
  • Test coverage: Added a comprehensive integration test (review-tab-refocus-refresh.spec.tsx) that verifies:
    • The Review tab initially displays file diffs correctly
    • External file edits made while unfocused are picked up after the window regains focus
    • The diff view updates to show the new content without requiring manual refresh

Implementation Details

  • Uses refs to capture the latest versions of loadChangedFiles, loadAllFileHunks, and files to avoid stale closures
  • The focus listener is only registered when a workspace is active (workspaceId dependency)
  • Handles the async nature of onFocusChanged() registration with proper cleanup logic
  • Only triggers refresh when the window gains focus (payload: true), not when it loses focus
    https://claude.ai/code/session_018Py2TEY7RzxTcMNYUmL19W

The Review tab only re-fetched file content on the "workspace-files-changed"
event, which the native file watcher never actually emits (its startup call
in Dashboard.tsx has been commented out). An already-modified file that gets
edited further also doesn't change jj's reported status, so even a plain
file-list refresh wouldn't reveal the new content. Re-fetch the file list and
hunks for the open files whenever the window regains focus (via Tauri's
onFocusChanged), so switching back to the app always shows current disk
content.

Adds scripts/screenshot/specs/review-tab-refocus-refresh.spec.tsx to verify.
@Ziinc Ziinc changed the title Refresh Review tab diffs on window focus to catch external edits fix: Refresh Review tab diffs on window focus to catch external edits Aug 7, 2026
@Ziinc
Ziinc merged commit 04a906c into main Aug 7, 2026
10 of 11 checks passed
@Ziinc
Ziinc deleted the claude/review-tab-stale-contents-6hwmid branch August 7, 2026 19:13
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.

2 participants