Skip to content

Fix stale diff views not refreshing on file or tree changes#4731

Open
Jinwoo-H wants to merge 2 commits into
mainfrom
Jinwoo-H/diff-tree-file-watcher
Open

Fix stale diff views not refreshing on file or tree changes#4731
Jinwoo-H wants to merge 2 commits into
mainfrom
Jinwoo-H/diff-tree-file-watcher

Conversation

@Jinwoo-H
Copy link
Copy Markdown
Contributor

@Jinwoo-H Jinwoo-H commented Jun 6, 2026

Summary

Fixes #4730 — diff tabs stayed stale after file or git changes, and re-clicking a node in the source-control or combined-diff tree did not refresh the view.

  • Bump diffContentReloadNonce when re-opening an existing single-file diff tab (openDiff / openBranchDiff / openCommitDiff) so cached bodies refetch
  • Reload unstaged/staged single-file diff tabs when the active file's git status entry changes (not the whole worktree)
  • Include staged diff tabs in external file-watch reload routing and overflow recovery
  • Combined diff: retry loaded/in-flight sections on tree re-navigation and external file changes, skipping dirty inline edits
  • Bust in-flight diff read dedup on forced reloads to avoid stale promise results

Review fixes (auto-review-fix)

  • Scoped git-status reload to the active file's status signature; skip duplicate fetch on initial tab open
  • Guard combined-diff reloads against dirty sections and in-flight loads
  • Stabilized combined-diff external-change listener deps via ref

Validation

  • pnpm vitest run — editor-panel-diff-reload, editor-autosave, editor, useEditorExternalWatch tests (149 passing)
  • pnpm run typecheck:web
  • Electron E2E: unstaged diff auto-reloads on external edit; re-click reloads without closing tab

Made with Orca 🐋

Diff tabs cached git snapshots and ignored re-clicks in the source-control
and combined-diff trees. Bump a reload nonce on re-open, refetch on git
status changes for unstaged/staged tabs, include staged diffs in file-watch
reload routing, and retry combined-diff sections on navigate or external edits
without clobbering dirty inline edits.

Co-authored-by: Orca <help@stably.ai>
Copy link
Copy Markdown
Contributor

@pullfrog pullfrog Bot left a comment

Choose a reason for hiding this comment

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

Important

One moderate correctness issue: retrySection in CombinedDiffViewer should bump generation to prevent stale in-flight fetches from flashing old content.

Reviewed changes — fixes stale diff views by adding a diffContentReloadNonce signal for re-opening existing diff tabs, scoping git-status reloads to the active file's entries, and extending the combined diff viewer to reload sections on tree navigation and external file changes.

  • Add diffContentReloadNonce to OpenFile — bumped on re-opening existing diff tabs via openDiff, openBranchDiff, and openCommitDiff; the panel effect clears cached content and force-reloads when the nonce changes.
  • Extract isReloadableSingleFileDiffTab and shouldReloadDiffOnGitStatusChange — replace inline diffSource checks across the panel, external events, and lazy-load effects.
  • Scope git-status reload to the active file — compute activeFileGitStatusSignature from only the matching status entries, eliminating spurious reloads when unrelated files change.
  • Include staged diff tabs in external file-watch routingisExternalReloadableEditorTab and getOpenFilesForExternalFileChange now match staged diffs, and getOverflowExternalReloadTargets routes them to overflow recovery.
  • Combined diff: reload on tree navigation and external changesrequestCombinedDiffSectionReload retries loaded/in-flight sections with dirty-edit guards; an external-change listener reloads matching uncommitted sections.

Note: 1 inline comment(s) dropped because they did not anchor to lines inside the PR diff:

  • src/renderer/src/components/editor/CombinedDiffViewer.tsx:627-648 (RIGHT) — start_line 627 (RIGHT) is not inside a diff hunk

Pullfrog  | Fix it ➔View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Diff tabs kept stale Monaco bodies because keepCurrent*Model reused models
when git-fetched content changed. Key standalone and combined diff viewers off
content signatures and reload nonces, bump section contentGeneration on retry,
and invalidate combined-diff caches on git-status or external file changes.

Add CDP E2E harnesses for local (9 scenarios) and Mac localhost SSH (4
scenarios) diff-reload verification.
Copy link
Copy Markdown
Contributor

@pullfrog pullfrog 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 new issues found. All prior review feedback addressed.

Reviewed changes — the new commit a00dc4a rotates Monaco diff model keys via content-signature-based identities, hardens combined-diff reload with git-status signature tracking, and adds E2E verification scripts.

  • Rotate Monaco diff model keys via content signaturesEditorContent.tsx keys DiffViewer with the content hash + reload nonce to force a fresh mount when fetched blobs change; ChangesModeView.tsx uses the shared getDiffContentSignature for the original-side model key rotation.
  • Bump contentGeneration in retrySection — addresses the prior review's generation concern. The combined-diff load scheduler's rerequest clears in-flight queue slots before re-enqueuing, and DiffSectionItem.tsx incorporates contentGeneration into its Monaco model path key.
  • Add git-status signature tracking to combined diffbuildCombinedGitStatusSignature scopes cache restores to matching sections; an effect reloads all loaded sections when git status entries for those files change.
  • Add module-level external-change listener for unmounted combined-diff tabs — invalidates the view state cache so remounts don't replay stale section bodies.
  • Extract shared predicates and utilitiesisReloadableSingleFileDiffTab, shouldReloadDiffOnGitStatusChange, isExternalReloadableEditorTab, and getDiffContentSignature replace inline checks across the editor panel, external events, and file watch subsystems.
  • Add three E2E verification scripts — Playwright CDP scripts (diff-reload-e2e-verify.mjs, diff-reload-ssh-e2e-verify.mjs, diff-reload-ssh-local-e2e-verify.mjs) cover local, SSH Docker container, and SSH localhost diff-reload scenarios.
  • Bust in-flight diff dedup on forced reloadsloadDiffContent now accepts { force?: boolean }; external-change events pass force: true to avoid stale promise results.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

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.

Diff views don't update when files change — must close and reopen tabs to see changes

1 participant