Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ describe("followPreviewSessions", () => {
useRightPanelStore
.getState()
.byThreadKey[threadKey]?.surfaces.filter((surface) => surface.kind === "preview")
.map((surface) => surface.id);
.map((surface) => surface.id) ?? [];

it("adds visible sessions as tabs and drops tabs whose session ended", () => {
setup();
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/hooks/useRightPanelSurfaceClose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ export function useRightPanelSurfaceClose(input: {
(left, right) => Number(left.id === activeId) - Number(right.id === activeId),
);
for (const surface of ordered) {
releaseSurfaceResources(threadRef, surface);
// Releasing a browser drops its session, which prunes the tab automatically; close it
// first so the close stays a user action that hides the panel after the last tab.
store.closeSurface(threadRef, surface.id);
releaseSurfaceResources(threadRef, surface);
}
const nextActiveSurface = selectActiveRightPanelSurface(
useRightPanelStore.getState().byThreadKey,
Expand Down
18 changes: 18 additions & 0 deletions apps/web/src/rightPanelStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,24 @@ describe("rightPanelStore", () => {
});
});

it("hides the panel when browser reconciliation removes its last session tab", () => {
const store = useRightPanelStore.getState();
store.openBrowser(refA, "tab-a");
store.reconcileBrowserSurfaces(refA, []);
expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
isOpen: false,
activeSurfaceId: null,
surfaces: [],
});

store.openBrowser(refA, "tab-b");
store.open(refA, "diff");
store.reconcileBrowserSurfaces(refA, []);
expect(
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA),
).toMatchObject({ isOpen: true, activeSurfaceId: "diff" });
});

it("moves a surface to a new index and keeps it there through browser reconciliation", () => {
const store = useRightPanelStore.getState();
store.openTerminal(refA, "term-1");
Expand Down
6 changes: 6 additions & 0 deletions apps/web/src/rightPanelStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -972,8 +972,14 @@ export const useRightPanelStore = create<RightPanelStoreState>()(
(surface) => surface.id === current.activeSurfaceId,
);
const fallbackBrowser = surfaces.find((surface) => surface.kind === "preview");
// A closed session tab was the last surface: hide the panel rather than leave it on
// the empty picker, as a user close would. A dropped `browser:new` placeholder does not count.
const closedLastSessionTab =
surfaces.length === 0 &&
current.surfaces.some((surface) => surface.kind === "preview" && surface.resourceId);
return {
...current,
isOpen: closedLastSessionTab ? false : current.isOpen,
surfaces,
activeSurfaceId: activeStillExists
? current.activeSurfaceId
Expand Down
Loading