Skip to content

fix(editor): reuse parked previews across tab groups - #19181

Open
nwparker wants to merge 2 commits into
mainfrom
split/11866-parked-preview-fix
Open

nwparker wants to merge 2 commits into
mainfrom
split/11866-parked-preview-fix

Conversation

@nwparker

@nwparker nwparker commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​264 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​264
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​132 $\color{#cf222e}{\Huge{\mathbf{−}}}$​113 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19

ELI5

After focusing a terminal, clicking another changed file now updates the preview parked in a neighboring split instead of opening a second preview over the terminal.

What Changed / Why

Part 1 of the split of #11866. Unpinned editor and diff previews reuse the existing preview across tab groups within the workspace. Explicitly targeted opens keep group scoping, and previews sharing an editor entity remain protected. Includes the editor open-call contract and parked-preview regression tests.

The optional Source Control side-split setting is isolated in #19182, based on this branch. Merge this fix first, then retarget part 2 to main.

Original implementation by Dan Cieslak (@dcieslak19973) in #11866; his Git commit authorship is preserved. This PR extracts and rebases his fix onto current main.

Linked Issue

Addresses the parked-preview bug in #11839. Split from #11866.

Visual Proof

These are the original PR’s Electron/CDP captures, reused as historical evidence; rendered validation was not rerun on this split head.

Before the click: preview parked beside the focused terminal.

Parked preview

After clicking another changed file: the parked preview is reused.

Preview reused

Testing

  • 56 tests passed on the isolated fix: parked-preview reuse, tab placement, open diff, close-file cleanup, and branch-diff snapshots.
  • Web typecheck and targeted oxlint passed.
  • Full lint, build, platform matrix, and fresh rendered validation are left to CI/follow-up review.

Review

Checked explicit group scoping, shared preview entities, per-file cleanup, and workspace isolation. No new platform shortcuts, filesystem operations, Git commands, execution-host assumptions, or remote wire fields. Existing folder/SSH editor paths remain in use.

Agent skill upstream boundary

  • Not applicable.

Extracted from #11866 by @dcieslak19973. Preserve explicit target-group scoping while unpinned previews reuse the parked tab.
@coderabbitai

coderabbitai Bot commented Sep 7, 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: Team

Run ID: 42a7dca9-7dae-466f-b53d-d39af291f6a7

📥 Commits

Reviewing files that changed from the base of the PR and between a280854 and 0820839.

📒 Files selected for processing (6)
  • src/renderer/src/store/slices/editor-parked-preview-reuse.test.ts
  • src/renderer/src/store/slices/editor/actions/open-conflict-file.ts
  • src/renderer/src/store/slices/editor/actions/open-file-apply.ts
  • src/renderer/src/store/slices/editor/actions/open-history-diff.ts
  • src/renderer/src/store/slices/editor/actions/open-unstaged-diff.ts
  • src/renderer/src/store/slices/editor/tabs/workspace-editor-item.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/store/slices/editor/actions/open-conflict-file.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The change adds worktree-scoped parked preview reuse across editor split groups. openWorkspaceEditorItem now accepts structured preview, target-group, and pinned-group options. Preview actions resolve slots with retargeting data. Vitest coverage verifies diff previews, file-explorer previews, repeated opens, permanent files, and targeted split behavior.

Merge Risk: 🔵 Low · up to 08208

Parked preview reuse now works across editor groups, but in a protected-preview ordering case it may create an additional preview tab rather than reusing an eligible parked tab. This is a bounded editor-tab behavior issue and should be addressed before relying on complete preview reuse.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: reusing parked editor previews across tab groups.
Description check ✅ Passed The description covers the main change, rationale, linked issue, visual proof, testing, review notes, and agent-skill boundary. The AI Disclosure, Notes, and Checklist sections are not included, but t…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: eaa8876f-4ec7-4aa2-8f2c-05518b851d2a

📥 Commits

Reviewing files that changed from the base of the PR and between e9af947 and a280854.

📒 Files selected for processing (9)
  • src/renderer/src/store/slices/editor-parked-preview-reuse.test.ts
  • src/renderer/src/store/slices/editor/actions/markdown-preview-actions.ts
  • src/renderer/src/store/slices/editor/actions/open-conflict-file.ts
  • src/renderer/src/store/slices/editor/actions/open-conflict-review.ts
  • src/renderer/src/store/slices/editor/actions/open-file-action.ts
  • src/renderer/src/store/slices/editor/actions/open-file-apply.ts
  • src/renderer/src/store/slices/editor/actions/open-history-diff.ts
  • src/renderer/src/store/slices/editor/actions/open-unstaged-diff.ts
  • src/renderer/src/store/slices/editor/tabs/workspace-editor-item.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.

})
store.getState().focusGroup('wt-1', groupAId)

store.getState().openDiff('wt-1', '/repo/a.ts', 'a.ts', 'typescript', false, { preview: true })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert the parked group’s active tab.

The current assertions verify placement, but not selection. Assert that state.groupsByWorktree['wt-1'] group B has activeTabId equal to the existing preview tab ID. Otherwise, the preview can remain parked while the test passes.

Comment on lines +71 to +76
const previewTab = tabsForWorktree.find(
(tab) =>
(!pinnedGroupId || tab.groupId === pinnedGroupId) &&
tab.isPreview &&
isEditorTabContentType(tab.contentType)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Skip protected previews when selecting a replacement slot.

If the first worktree preview shares its entity with another editor tab, this function returns null at Line 95. It does not inspect a later unshared preview in another group. The caller then creates an additional preview instead of reusing that parked preview.

Select the first preview that is both eligible and not shared.

Proposed fix
-  const previewTab = tabsForWorktree.find(
-    (tab) =>
-      (!pinnedGroupId || tab.groupId === pinnedGroupId) &&
-      tab.isPreview &&
-      isEditorTabContentType(tab.contentType)
-  )
+  const previewTab = tabsForWorktree.find(
+    (candidate) =>
+      (!pinnedGroupId || candidate.groupId === pinnedGroupId) &&
+      candidate.isPreview &&
+      isEditorTabContentType(candidate.contentType) &&
+      !tabsForWorktree.some(
+        (tab) =>
+          tab.id !== candidate.id &&
+          tab.entityId === candidate.entityId &&
+          isEditorTabContentType(tab.contentType)
+      )
+  )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const previewTab = tabsForWorktree.find(
(tab) =>
(!pinnedGroupId || tab.groupId === pinnedGroupId) &&
tab.isPreview &&
isEditorTabContentType(tab.contentType)
)
const previewTab = tabsForWorktree.find(
(candidate) =>
(!pinnedGroupId || candidate.groupId === pinnedGroupId) &&
candidate.isPreview &&
isEditorTabContentType(candidate.contentType) &&
!tabsForWorktree.some(
(tab) =>
tab.id !== candidate.id &&
tab.entityId === candidate.entityId &&
isEditorTabContentType(tab.contentType)
)
)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

This PR makes unpinned editor/diff preview reuse worktree-scoped instead of group-scoped, so a preview parked in a neighboring split is recycled rather than a second preview opening over the focused terminal (the "small fix" half of #11839).

  • resolveReplaceablePreviewSlot — replaces getReplaceablePreviewFileId. Unpinned opens find the parked preview tab anywhere in the worktree and return its index plus a retargetGroupId; pinned opens (pinnedGroupId set) keep the old group scoping, and the shared-entity guard is preserved.
  • openWorkspaceEditorItem — trailing positional args become an open options object (isPreview/targetGroupId/pinnedGroupId). Unpinned previews re-activate an existing tab for the same entity wherever it lives before falling through to group resolution/creation.
  • Call-site migration — open-file-action, open-file-apply, open-unstaged-diff, open-history-diff, open-conflict-file, open-conflict-review, and markdown-preview-actions all thread pinnedGroupId through and reuse the shared slot helper. No stale callers of the old signature remain.
  • Tests — new editor-parked-preview-reuse.test.ts (4 real slice-integration tests) covers cross-group recycling, file-explorer preview opens, same-file re-activation, and pinned-group scoping; assertions are exact enough to catch the original bug.

I verified the change end-to-end against the slice implementation and ran the affected test families (331 tests green, including the existing shared-preview-diff and Source Control preview-open suites). One informational note for scope tracking: the "only one preview tab per worktree" acceptance criterion from #11839 is intentionally not fully enforced here — two pinned previews in different groups can still coexist — which is consistent with this being the scoped small fix.

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

@nwparker

nwparker commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the two reproduced regressions in 0820839. My earlier readiness assessment missed these cases and is superseded by this correction.

  • Preview replacement now prefers the resolved target group before searching neighboring groups. Two simultaneous previews no longer make an unpinned open evict the wrong pane’s preview.
  • The OpenFile-only fallback now requires no resolved group and no tab-layer entries. Promoting a preview tab can leave OpenFile.isPreview stale; that stale flag no longer permits removing its backing file.
  • Cross-group same-file reactivation is restricted to preview tabs, preserving local side-by-side opens of permanent files.

Added four regression tests covering focused-group preference, promoted editor backing state, promoted diff backing state, and permanent-file side-by-side opening. The original parked-preview and explicit-target tests continue to pass.

Validation: 106 focused editor tests, web typecheck, targeted oxlint, and diff checks pass. The correction is also incorporated into stacked PR #19182, where 51 focused editor/Source Control/layout tests and web typecheck pass. Fresh rendered Electron checks were not run for this correction.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

This delta hardens the base fix against two edge cases the first pass left open: it prefers the focused group's parked preview when several exist, and it stops a stale OpenFile.isPreview (left behind by tab-layer promotion) from overwriting a permanent tab's backing file.

  • resolveReplaceablePreviewSlot gains a resolved-group argument — unpinned opens now prefer the preview parked in the resolved (focused) group before falling back to the first candidate, so recycling tracks focus rather than insertion order. Pinned opens are unchanged.
  • openWorkspaceEditorItem reactivation is preview-only — the existingAnywhere scan now requires tab.isPreview, so an unpinned open of an already-permanent entity reopens it locally instead of stealing focus from the other group.
  • Headless fallback is gated tighter — the openFiles scan now only runs when there are no pins, no resolved group, and no tabs, preventing a promoted tab's stale isPreview from being recycled out from under it.
  • Four new regression tests cover focused-group preference, promoted-tab backing-file preservation, local permanent reopen, and promoted-diff preservation.

One informational note for scope tracking: the new guard works around a pre-existing asymmetry rather than fixing it — activateTab promotes a preview tab to permanent at the tab layer but leaves OpenFile.isPreview stale (the new test at editor-parked-preview-reuse.test.ts:220 documents this). Other readers of OpenFile.isPreview could still observe a permanent tab as a preview; worth a follow-up but out of scope for this small fix.

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

@dcieslak19973

Copy link
Copy Markdown
Contributor

The CI red here is an unrelated flake, not this change:

  • The only failing test is src/main/runtime/rpc/methods/structured-agent-session-adoption-replay.test.ts ("republishes from durable identity after the source disappears and account selection drifts") — agent-session RPC replay, which isn't in this PR's diff. This PR only touches src/renderer/src/store/slices/editor/**. verify is just the aggregate of that one failure.
  • It's a race: the replay returns an agent_session_operation_unknown refusal (ok:false) instead of ok:true.
  • Strongest signal: the stacked feat(source-control): optionally open diffs in a side split #19182 contains all of these same commits plus the feature, and it passes the identical test / tests node 24 6/8 shard and verify green (that PR is CLEAN).

A re-run of the failed job should clear it. Thanks again for the clean split and keeping the authorship/credit.

This branch has not been deployed

No deployments
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