Skip to content

fix(editor): keep an invalidated diff visible until its reload lands - #13777

Merged
nwparker merged 1 commit into
mainfrom
nwparker/editor-diff-content-stale
Aug 11, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/editor-diff-content-stale

Conversation

@nwparker

@nwparker nwparker commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Deferred follow-up to #13634.

That PR made invalidateFileContent mark cache entries stale instead of deleting them, so revealing a hidden editor panel swaps bytes in place rather than flashing Loading…. invalidateDiffContent was left deleting its entry, so revealing a hidden/inactive diff still flashed Loading diff.... Two reviewers raised it separately; it was out of scope at the time.

Safety: the diff path has its own generation fence

Verified before mirroring the change — the diff read is fenced identically to the file read:

  • diffReadGenerationRef is bumped by invalidateDiffContent (useEditorPanelContentState.ts), exactly as fileReadGenerationRef is by invalidateFileContent.
  • loadDiffContent captures its generation before any await and re-checks diffReadGenerationRef.current[file.id] !== generation on both the success and the error path before calling setDiffContents.

So a superseded in-flight diff read can never write back over fresh content, which is what makes retaining the bytes safe. (Covered by the pre-existing test invalidates a hidden diff nonce without reading until reveal, which still asserts the stale read is dropped.)

Changes

  • DiffContent gains an optional isStale flag (renderer-local extension of the shared GitDiffResult wire type — no wire change, so no remote-compat impact).
  • invalidateDiffContent marks the entry stale instead of deleting it.
  • needsDiffRead treats a stale entry as needing a read, so the lazy reveal effect still refetches exactly once (same RPC count as before).
  • The git-status reload effect's "the lazy-load effect already fetches this" guard now treats a stale entry like a missing one. Without this, a status change arriving in the same commit as a reveal would fire both the lazy read and a forced read — a double RPC that the delete-based code avoided.

Fresh reads and error results overwrite the whole entry, so isStale clears naturally.

Test

New: keeps an invalidated diff on screen until the reveal read lands in useEditorPanelVisibilityContentState.test.tsx — asserts the diff is still 'old diff' (not undefined, which is the only thing EditorContent/ChangesModeView key their Loading diff... placeholder on) both right after invalidation and while the reveal read is in flight, then that the fresh read replaces it with isStale gone, in exactly 2 RPCs.

Proven discriminating: reverting only the invalidateDiffContent body back to delete fails 3 tests —

× keeps an invalidated diff on screen until the reveal read lands
× invalidates a hidden Git-status diff without reading until reveal
× invalidates an inactive cached Changes diff after an external edit
AssertionError: expected undefined to be 'old diff'

The latter two are existing tests updated from toBeUndefined() to asserting the retained stale entry.

Verification

  • vitest run src/renderer/src/components/editor/ — 167 files, 1123 tests passed
  • tsc --noEmit -p config/tsconfig.tc.web.json — clean
  • oxlint clean on touched files

No max-lines disables added or bumped. No UI/token changes (the fix is purely that the existing viewer keeps rendering). Behavior is host-agnostic — it lives in renderer cache bookkeeping, so SSH hosts and folder workspaces are covered identically.

Not done

Made with Orca 🐋

Mark invalidated diff content stale instead of dropping it, mirroring the file-content treatment from #13634. The diff read-generation fence (diffReadGenerationRef) already rejects a superseded read's write-back, so retaining the bytes and swapping them on arrival is safe and keeps every RPC saving -- it just stops the loading placeholder flashing on each reveal.

The git-status reload effect now treats a stale entry like a missing one so the lazy-load effect stays the single fetcher for it.

Co-authored-by: Orca <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5f5beb93-f5a5-4615-9c0e-b2e4c4b39443

📥 Commits

Reviewing files that changed from the base of the PR and between b3965f3 and f71eea0.

📒 Files selected for processing (3)
  • src/renderer/src/components/editor/editor-panel-content-types.ts
  • src/renderer/src/components/editor/useEditorPanelContentState.ts
  • src/renderer/src/components/editor/useEditorPanelVisibilityContentState.test.tsx

📝 Walkthrough

Walkthrough

The editor now retains cached diff content during invalidation and marks it with isStale. Stale or missing diffs trigger reads, while Git-status reloads avoid duplicate requests. Tests verify stale diff retention while hidden and during reveal-triggered loading, followed by replacement with fresh content.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and tests, but it omits the required Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes sections. Add the required sections, mark each test, document AI review and macOS/Linux/Windows compatibility checks, provide the security audit, and state whether screenshots are needed.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: keeping invalidated editor diffs visible until reload completes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit 12f58f6 into main Aug 11, 2026
45 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#13777)

Mark invalidated diff content stale instead of dropping it, mirroring the file-content treatment from stablyai#13634. The diff read-generation fence (diffReadGenerationRef) already rejects a superseded read's write-back, so retaining the bytes and swapping them on arrival is safe and keeps every RPC saving -- it just stops the loading placeholder flashing on each reveal.

The git-status reload effect now treats a stale entry like a missing one so the lazy-load effect stays the single fetcher for it.

Co-authored-by: Orca <[email protected]>
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