Skip to content

Commit 462c56d

Browse files
committed
fix(web): restore retained terminal visibility on session changes
1 parent 9ede4da commit 462c56d

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎apps/web/src/components/ThreadTerminalDrawer.permissions.browser.test.tsx‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ vi.mock(import("../state/session"), async (original) => {
8383
});
8484

8585
import { TerminalViewport } from "./ThreadTerminalDrawer";
86+
import { KeptViewLifetimeContext, createKeptViewLifetime } from "./keptView";
8687

8788
const threadRef = {
8889
environmentId: EnvironmentId.make("secondary-terminal"),
@@ -112,6 +113,38 @@ afterEach(async () => {
112113
vi.unstubAllGlobals();
113114
});
114115

116+
it("keeps a replacement terminal session visible while the drawer stays open", async () => {
117+
const lifetime = createKeptViewLifetime();
118+
const viewport = (terminalId: string) => (
119+
<KeptViewLifetimeContext value={lifetime}>
120+
<TerminalViewport
121+
advancedTypography={false}
122+
threadRef={threadRef}
123+
threadId={threadRef.threadId}
124+
terminalId={terminalId}
125+
terminalLabel="Terminal"
126+
cwd="/repo"
127+
onSessionExited={state.otherCommand}
128+
focusRequestId={0}
129+
autoFocus={false}
130+
visible={true}
131+
resizeEpoch={0}
132+
drawerHeight={200}
133+
keybindings={[]}
134+
/>
135+
</KeptViewLifetimeContext>
136+
);
137+
try {
138+
await act(async () => root.render(viewport("terminal-1")));
139+
expect(state.createSurface.mock.calls[0]![1].visible).toBe(true);
140+
await act(async () => root.render(viewport("terminal-2")));
141+
expect(state.createSurface).toHaveBeenCalledTimes(2);
142+
expect(state.createSurface.mock.calls[1]![1].visible).toBe(true);
143+
} finally {
144+
lifetime.dispose();
145+
}
146+
});
147+
115148
it("rechecks the target terminal grant when a retained surface callback reports a resize", async () => {
116149
await act(async () =>
117150
root.render(

‎apps/web/src/components/ThreadTerminalDrawer.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,9 @@ function TerminalSessionViewport({
610610
useEffect(() => {
611611
const mount = containerRef.current;
612612
if (!mount) return;
613+
// Session cleanup can hide the surface while the drawer remains visible.
614+
visibleRef.current = visible;
615+
terminalRef.current?.setVisible(visible);
613616
const surfaceKey = [environmentId, threadId, terminalId, cwd, worktreePath, runtimeEnvKey].join(
614617
"\u0000",
615618
);

0 commit comments

Comments
 (0)