Skip to content

Commit 7b5340c

Browse files
committed
fix(web): keep unavailable workspace tabs closed
1 parent 66155d6 commit 7b5340c

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎apps/web/src/reopenClosedView.test.ts‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ describe("reopenClosedView", () => {
6666
it("restores saved file and pull request tabs without creating resources", async () => {
6767
const openPreview = vi.fn();
6868
const openTerminal = vi.fn();
69-
const options = { openPreview, openTerminal, closeTerminal: vi.fn(), workspace: null };
69+
const options = {
70+
openPreview,
71+
openTerminal,
72+
closeTerminal: vi.fn(),
73+
workspace: { cwd: "/repo" },
74+
};
7075
expect(
7176
await reopenClosedView(
7277
{
@@ -106,6 +111,32 @@ describe("reopenClosedView", () => {
106111
expect(openTerminal).not.toHaveBeenCalled();
107112
});
108113

114+
it("does not reopen workspace tabs without an available project", async () => {
115+
const options = {
116+
openPreview: vi.fn(),
117+
openTerminal: vi.fn(),
118+
closeTerminal: vi.fn(),
119+
workspace: null,
120+
};
121+
for (const surface of [
122+
{ kind: "files", id: "files" },
123+
{
124+
kind: "file",
125+
id: "file:src/app.ts",
126+
relativePath: "src/app.ts",
127+
revealLine: null,
128+
revealRequestId: 0,
129+
},
130+
] as const) {
131+
expect(await reopenClosedView({ kind: "panel-tab", threadRef, surface }, options)).toBe(
132+
false,
133+
);
134+
}
135+
expect(
136+
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, threadRef).surfaces,
137+
).toEqual([]);
138+
});
139+
109140
it("recreates a browser tab with saved URL, viewport and profile, then selects its new ID", async () => {
110141
const openPreview = vi.fn(async () => AsyncResult.success({ ...snapshot, tabId: "new-tab" }));
111142
const result = await reopenClosedView(

‎apps/web/src/reopenClosedView.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ export async function reopenClosedView(
157157
return true;
158158
}
159159
const surface = view.surface;
160+
if (
161+
!options.workspace &&
162+
(surface.kind === "files" || (surface.kind === "file" && !surface.attachment))
163+
)
164+
return false;
160165
switch (surface.kind) {
161166
case "preview":
162167
if (surface.resourceId !== null) return false;

0 commit comments

Comments
 (0)