Skip to content

perf(renderer): mount jump palette content only while open - #7617

Closed
brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/perf-jump-palette-gating
Closed

brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/perf-jump-palette-gating

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem

WorktreeJumpPalette stays mounted for the whole session once opened (App.tsx lazy-mounts it and never unmounts). #7558 gated the two hottest status-map subscriptions (selectPaletteStatusInputs) behind visible || lingering, but ~30 other store subscriptions in the component stayed live unconditionally — prCache, issueCache, retainedAgentsByPaneKey, sleepingAgentSessionsByPaneKey, unifiedTabsByWorktree, browserPagesByWorkspace, and more. Every moderate-frequency write to any of them re-rendered the closed palette (and re-ran its ~30 useMemos) during ordinary agent/terminal use.

Fix

Finish #7558's approach structurally instead of slice-by-slice:

  • Shell (WorktreeJumpPalette, always mounted): subscribes to a single boolean (activeModal === 'worktree-palette'), owns the existing 300ms close-animation linger timer and the create-lookup request guard, and mounts the content only while visible || lingering. Closed cost collapses to one boolean selector.
  • Content (WorktreeJumpPaletteContent, same file — it's grandfathered in the max-lines baseline): all previous subscriptions, memos, and dialog rendering, unchanged. The selectPaletteStatusInputs(s, visible || lingering) gate is kept verbatim so #7558's close-animation freshness semantics are preserved exactly.

Behavior preserved:

  • Shortcut / open while closed: Cmd+J lives above the component (menu accelerator → IPC → useIpcEvents → openModal), so it opens the palette from the fully unmounted state.
  • Open freshness: content mounts on the same render visible flips true and subscribes live immediately; open-time compute is the same work the open palette already did after #7558 (status inputs change identity on open, so downstream memos recomputed anyway).
  • Close animation: content lingers 300ms past close with live status maps — no empty-row flash mid fade-out; then unmounts.
  • Pending create lookups: the request guard moved to the shell so it outlives content unmounts — reopening still invalidates a pending GH work-item lookup, exactly as before.

Tests

New WorktreeJumpPalette.closed-render-gating.test.tsx (render-count pattern, extends #7558's selector tests which still pass unchanged):

  • closed palette: identity churn on prCache/issueCache/retainedAgentsByPaneKey/unifiedTabsByWorktree/agentStatusByPaneKey/runtimePaneTitlesByTabId → zero content renders
  • data mutated while closed appears on the very first open (no stale snapshot)
  • opening from the unmounted state via the store action the Cmd+J IPC handler drives
  • live status-map subscription while open and during the linger window (positive controls), unmount + zero renders after the linger expires

vitest on all 6 palette-related suites: 48/48 green. Full pnpm typecheck clean. check:max-lines-ratchet OK (no new suppressions).

Made with Orca 🐋

#7558 gated the two hottest status-map subscriptions behind
visible-or-lingering, but ~30 other store slices (prCache, issueCache,
retainedAgentsByPaneKey, unifiedTabsByWorktree, browserPagesByWorkspace, ...)
stayed subscribed while the palette was closed, re-rendering the whole
always-mounted component on ordinary agent/terminal churn.

Generalize the gate structurally: a tiny always-mounted shell subscribes only
to activeModal (one boolean selector) and mounts WorktreeJumpPaletteContent
only while visible or lingering through the close animation. The linger window
and the selectPaletteStatusInputs gate keep #7558's close-animation freshness
exactly; the create-lookup guard moves to the shell so a reopen still
invalidates a pending GH work-item lookup across content unmounts. Cmd+J lives
above the component (menu accelerator -> IPC -> openModal), so opening from
the unmounted state is unchanged.

Closed-render-count tests pin the seam: zero content renders on store churn
while closed, fresh data on open, live maps during the linger window, and
unmount after it.

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

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

WorktreeJumpPalette is refactored into a shell component and a newly exported WorktreeJumpPaletteContent component. The shell introduces a lingering state governed by a renamed PALETTE_CLOSE_LINGER_MS constant, keeping content mounted briefly after the modal closes, and now creates createLookupGuard itself, passing it down as a prop. The status-input subscription gate changes from visible || statusInputsLingering to visible || lingering. A related comment in the status-inputs module is updated to reflect the new gating semantics. A new test suite validates closed-state render gating, including no renders during closed churn, immediate display of updates on open, open/close via store actions, and linger-window unmount timing.

Sequence Diagram(s)

sequenceDiagram
  participant Store
  participant WorktreeJumpPalette
  participant WorktreeJumpPaletteContent

  Store->>WorktreeJumpPalette: closeModal (visible=false)
  WorktreeJumpPalette->>WorktreeJumpPalette: start lingering timeout
  WorktreeJumpPalette->>WorktreeJumpPaletteContent: render while visible || lingering
  WorktreeJumpPaletteContent->>Store: subscribe status inputs (visible || lingering)
  WorktreeJumpPalette-->>WorktreeJumpPalette: timeout elapses, lingering=false
  WorktreeJumpPalette--xWorktreeJumpPaletteContent: unmount content
Loading

Related PRs: None identified.

Suggested labels: renderer, tests, refactor

Suggested reviewers: None identified.

🐰 A palette that lingers just a beat,
Then fades away, its work complete,
Guards survive the closing door,
Tests confirm what came before.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change, but it omits the required Summary, Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes sections. Rewrite the PR description using the repository template and add the missing sections, especially testing, review, security, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: mounting jump palette content only while open.
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.

@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.

🧹 Nitpick comments (4)
src/renderer/src/components/WorktreeJumpPalette.tsx (2)

329-343: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Trim "Why" comments to 1-2 lines per guideline.

Several new comment blocks (Lines 329-336, 339-343, 395-398) run 4-8 lines each. As per coding guidelines, **/*.{ts,tsx,js,jsx} comments explaining non-obvious behavior should be "Keep comments short — one or two lines, capturing only the non-obvious reason."

Also applies to: 395-398

Source: Coding guidelines


337-377: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Consider extracting WorktreeJumpPaletteContent into its own module.

This file is ~2355 lines. As per coding guidelines, **/*.{ts,tsx,js,jsx} files should be split rather than accumulate further: "Split the file, extract focused modules, move fixtures/builders into named files, or otherwise reduce the counted lines instead." This PR already carves out a clean shell/content boundary at Line 369 — moving WorktreeJumpPaletteContent (and its ~2000 lines of hooks/handlers/JSX) to a dedicated file would be a natural, low-risk follow-up.

Source: Coding guidelines

src/renderer/src/components/worktree-jump-palette-status-inputs.ts (1)

17-23: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Comment exceeds the 1-2 line guideline.

The rewritten rationale spans 7 lines. As per coding guidelines, **/*.{ts,tsx,js,jsx} "Why" comments should be "one or two lines, capturing only the non-obvious reason." Consider trimming to the core point (frozen fallback + shallow-equal reference stability) and dropping the historical narrative.

Source: Coding guidelines

src/renderer/src/components/WorktreeJumpPalette.closed-render-gating.test.tsx (1)

217-254: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Good linger-unmount coverage; consider adding a guard-persistence regression test.

This test correctly verifies the linger window and post-linger unmount. One architectural invariant introduced by this PR isn't directly exercised here: createLookupGuard must now survive full content unmount/remount (previously content never unmounted after first open, so the guard's lifetime was never at risk). A regression test that opens the palette, triggers a create-lookup, closes past the linger window (full unmount), reopens, and asserts the guard was invalidated exactly once (or that stale lookups are rejected) would protect this newly-fragile contract against future refactors that accidentally recreate the guard per content mount.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 930e60fd-abfb-4622-9a3a-b4ec653fd40b

📥 Commits

Reviewing files that changed from the base of the PR and between 9a3bf12 and 95eb4b1.

📒 Files selected for processing (3)
  • src/renderer/src/components/WorktreeJumpPalette.closed-render-gating.test.tsx
  • src/renderer/src/components/WorktreeJumpPalette.tsx
  • src/renderer/src/components/worktree-jump-palette-status-inputs.ts

@nwparker

Copy link
Copy Markdown
Contributor

Closing as done: main's WorktreeJumpPalette.tsx already mounts content only while open, with the close-animation delay.

@nwparker nwparker closed this Oct 14, 2026
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