diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 6f092294c..5daff8422 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -121,7 +121,6 @@ function App(): React.JSX.Element { const showActiveOnly = useAppStore((s) => s.showActiveOnly) const filterRepoIds = useAppStore((s) => s.filterRepoIds) const persistedUIReady = useAppStore((s) => s.persistedUIReady) - const rightSidebarOpen = useAppStore((s) => s.rightSidebarOpen) const rightSidebarWidth = useAppStore((s) => s.rightSidebarWidth) const isFullScreen = useAppStore((s) => s.isFullScreen) const settings = useAppStore((s) => s.settings) @@ -680,7 +679,14 @@ function App(): React.JSX.Element { {activeView === 'settings' ? : !activeWorktreeId ? : null} - {showSidebar && rightSidebarOpen ? : null} + {/* Why: keep RightSidebar mounted even when closed so that its + child components (FileExplorer, SourceControl, etc.) and their + filesystem watchers + cached directory trees survive across + open/close toggles. Without this, every Ctrl+L remounts the + entire subtree, triggering watchWorktree + readDir + branchCompare + IPC calls that freeze Windows for seconds. The sidebar already + renders at width 0 when closed via useSidebarResize. */} + {showSidebar ? : null} diff --git a/src/renderer/src/components/right-sidebar/ChecksPanel.tsx b/src/renderer/src/components/right-sidebar/ChecksPanel.tsx index 11fe3ee49..23a75726d 100644 --- a/src/renderer/src/components/right-sidebar/ChecksPanel.tsx +++ b/src/renderer/src/components/right-sidebar/ChecksPanel.tsx @@ -24,6 +24,13 @@ export default function ChecksPanel(): React.JSX.Element { const fetchPRForBranch = useAppStore((s) => s.fetchPRForBranch) const gitConflictOperationByWorktree = useAppStore((s) => s.gitConflictOperationByWorktree) + // Why: the sidebar stays mounted when closed (for performance). Gate + // polling on visibility so we don't fetch checks/comments in the background + // when the panel isn't visible to the user. + const rightSidebarOpen = useAppStore((s) => s.rightSidebarOpen) + const rightSidebarTab = useAppStore((s) => s.rightSidebarTab) + const isPanelVisible = rightSidebarOpen && rightSidebarTab === 'checks' + const fetchPRChecks = useAppStore((s) => s.fetchPRChecks) const fetchPRComments = useAppStore((s) => s.fetchPRComments) const resolveReviewThread = useAppStore((s) => s.resolveReviewThread) @@ -143,7 +150,7 @@ export default function ChecksPanel(): React.JSX.Element { // Fetch checks on mount + poll with exponential backoff useEffect(() => { - if (!prNumber) { + if (!prNumber || !isPanelVisible) { setChecks([]) return } @@ -171,7 +178,7 @@ export default function ChecksPanel(): React.JSX.Element { clearTimeout(pollRef.current) } } - }, [fetchChecks, prNumber]) + }, [fetchChecks, isPanelVisible, prNumber]) // Fetch comments once when PR changes (no polling — comments change infrequently). // The manual refresh path calls this directly; the auto-fetch effect below uses @@ -200,7 +207,7 @@ export default function ChecksPanel(): React.JSX.Element { ) useEffect(() => { - if (!repo || !prNumber) { + if (!repo || !prNumber || !isPanelVisible) { setComments([]) return } @@ -225,7 +232,7 @@ export default function ChecksPanel(): React.JSX.Element { return () => { cancelled = true } - }, [repo, prNumber, fetchPRComments]) + }, [repo, prNumber, isPanelVisible, fetchPRComments]) const handleRefresh = useCallback(async () => { if (!repo || !branch) { diff --git a/src/renderer/src/components/right-sidebar/SourceControl.tsx b/src/renderer/src/components/right-sidebar/SourceControl.tsx index 6765f10f7..2a1dccc35 100644 --- a/src/renderer/src/components/right-sidebar/SourceControl.tsx +++ b/src/renderer/src/components/right-sidebar/SourceControl.tsx @@ -160,7 +160,12 @@ function SourceControlInner(): React.JSX.Element { const conflictOperation = activeWorktreeId ? (gitConflictOperationByWorktree[activeWorktreeId] ?? 'unknown') : 'unknown' - const isBranchVisible = rightSidebarTab === 'source-control' + const rightSidebarOpen = useAppStore((s) => s.rightSidebarOpen) + // Why: gate polling on both the active tab AND the sidebar being open. + // The sidebar now stays mounted when closed (for performance), so without + // this guard the branchCompare interval and PR fetch would keep running + // with no visible consumer, wasting git process spawns and API calls. + const isBranchVisible = rightSidebarTab === 'source-control' && rightSidebarOpen useEffect(() => { if (!activeRepo || isFolder) { diff --git a/src/renderer/src/components/right-sidebar/index.tsx b/src/renderer/src/components/right-sidebar/index.tsx index 0dca319ec..f635abeab 100644 --- a/src/renderer/src/components/right-sidebar/index.tsx +++ b/src/renderer/src/components/right-sidebar/index.tsx @@ -1,4 +1,4 @@ -import React, { useLayoutEffect, useMemo, useRef } from 'react' +import React, { useMemo } from 'react' import { Files, Search, GitBranch, ListChecks } from 'lucide-react' import { useAppStore } from '@/store' import { cn } from '@/lib/utils' @@ -136,21 +136,8 @@ function RightSidebarInner(): React.JSX.Element { ? rightSidebarTab : visibleItems[0].id - // Why: suppress CSS width transitions when the sidebar opens so the - // width snaps to 320 px instantly instead of animating from 0→320 px. - // Without this, Chromium fires the transition causing the terminal - // container to resize through intermediate widths. Each intermediate - // width triggers a synchronous xterm scrollback reflow that blocks the - // renderer for seconds on Windows. - // - // useLayoutEffect + direct DOM style manipulation runs synchronously - // BEFORE the browser paints, so the transition is killed before Chromium - // can start it. A useState-based approach has a timing race: the state - // update triggers a re-render that arrives one frame too late. - const prevOpenRef = useRef(rightSidebarOpen) - const activityBarSideWidth = activityBarPosition === 'side' ? ACTIVITY_BAR_SIDE_WIDTH : 0 - const { containerRef, isResizing, onResizeStart } = useSidebarResize({ + const { containerRef, onResizeStart } = useSidebarResize({ isOpen: rightSidebarOpen, width: rightSidebarWidth, minWidth: MIN_WIDTH, @@ -160,22 +147,6 @@ function RightSidebarInner(): React.JSX.Element { setWidth: setRightSidebarWidth }) - useLayoutEffect(() => { - if (rightSidebarOpen && !prevOpenRef.current) { - const el = containerRef.current - if (el) { - // Kill the transition before the browser paints the width change. - el.style.transition = 'none' - // Restore CSS-class-driven transitions in the next frame so close - // animations and drag-resize still animate smoothly. - requestAnimationFrame(() => { - el.style.transition = '' - }) - } - } - prevOpenRef.current = rightSidebarOpen - }, [rightSidebarOpen, containerRef]) - const panelContent = (
{/* Why: sidebar panels no longer use key={activeWorktreeId} because @@ -206,8 +177,13 @@ function RightSidebarInner(): React.JSX.Element {
{/* Panel content area */}