fix(vcs): keep the log mounted while another Git tab is shown (#5454)

Switching between Console / Worktrees and Log in the Git tool window stuttered on every click of Log: the log view was unmounted whenever another tab was shown and rebuilt on return. The log now stays mounted (inert and unfocusable) while hidden; switching back takes ~33 ms instead of 70–100 ms.
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-24 07:30:01 +08:00
1 джерело 2f8d5f5118
коміт de11bc02f1
3 files changed
+65 -5

No files matched your search

+17
Переглянути файл
@@ -1,9 +1,26 @@
.root {
position: relative;
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
/* Absolute in both states, so hiding and showing the log doesn't lay it out again. */
.logHost {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
}
.logHidden {
content-visibility: hidden;
z-index: -1;
}
/* WebKit leaves a stale selection highlight on a subtree whose rendering was skipped when the selection cleared. */
.logHidden[data-selection] {
content-visibility: visible;
opacity: 0;
}
.headerTabs {
min-width: 0;
border: 0;
+19 -5
Переглянути файл
@@ -14,6 +14,7 @@ import {
useFrozenWhileWindowResizes,
} from "@/ui";
import { copySelectionOnKeyDown } from "@/ui/selectableText";
import { useSelectionVisibility } from "@/ui/useSelectionBoundary";
import { spanStyle } from "@/ui/ansi";
import clsx from "clsx";
import { useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
@@ -34,6 +35,7 @@ import { LogScope } from "./LogScope";
import {
closeLogTab,
initLogBranchFilter,
isLogTab,
logState,
refsSignature,
reloadLog,
@@ -85,6 +87,15 @@ export function GitToolWindow() {
// window drag; they follow the window once it stops.
const root = useRef<HTMLDivElement>(null);
useFrozenWhileWindowResizes(root);
// The last log tab shown stays mounted (hidden, keeping its layout) while another tab is shown,
// so switching back to it neither rebuilds its rows, graph and branch tree nor reloads it.
const logTabs = useGitLog((s) => s.logTabs);
const logShown = isLogTab(shown, logTabs);
const [lastLog, setLastLog] = useState<string | null>(null);
if (logShown && lastLog !== shown) setLastLog(shown);
const keptLog = logShown ? shown : lastLog && isLogTab(lastLog, logTabs) ? lastLog : null;
const logHost = useRef<HTMLDivElement>(null);
useSelectionVisibility(logHost, !!keptLog && (available || external));
if (!available && !external)
return (
<EmptyState title="Version control is not configured">
@@ -107,11 +118,14 @@ export function GitToolWindow() {
<ConsoleView />
) : shown === "worktrees" ? (
<WorktreesPanel className={styles.worktrees} listClassName={styles.worktreeList} />
) : (
// Each log tab has its own view (its filters and commits are swapped into the store).
<LogScope id={shown}>
<LogView key={shown} />
</LogScope>
) : null}
{keptLog && (
<div ref={logHost} className={clsx(styles.logHost, !logShown && styles.logHidden)} inert={!logShown}>
{/* Each log tab has its own view (its filters and commits are swapped into the store). */}
<LogScope id={keptLog}>
<LogView key={keptLog} />
</LogScope>
</div>
)}
</div>
);