Skip to content

Commit 43e30c9

Browse files
fix(web): keep a Files browser open across composer draft switches
Open in browser shared the Add to chat lifetime, which ends when the composer moves to another draft. Entering or leaving queued-message editing before the file was ready therefore dropped the browser even though the thread stayed on screen. Opening a browser now follows a lifetime keyed by the thread alone. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 9f65c5d commit 43e30c9

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

‎apps/web/src/panels/files/FilesSidePanel.test.tsx‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,15 @@ function composerOf(threadRef: ScopedThreadRef) {
240240
return composers.get(key)!;
241241
}
242242

243-
async function renderFileFor(threadRef: ScopedThreadRef, relativePath: string | null = "src/a.ts") {
243+
async function renderFileFor(
244+
threadRef: ScopedThreadRef,
245+
relativePath: string | null = "src/a.ts",
246+
composerDraftTarget: PanelHost["composerDraftTarget"] = threadRef,
247+
) {
244248
const host: PanelHost = {
245249
threadRef,
246250
visible: true,
247-
composerDraftTarget: threadRef,
251+
composerDraftTarget,
248252
workspaceMutationId: null,
249253
sendAnnotation: () => undefined,
250254
};
@@ -494,6 +498,17 @@ describe("files actions that settle late", () => {
494498
expect(browsersOf(threadRef).map((surface) => surface.id)).toEqual(["browser:tab-1"]);
495499
});
496500

501+
it("still opens a browser after the composer switches drafts in the same thread", async () => {
502+
const threadRef = refOn("environment-a");
503+
await renderFileFor(threadRef, "index.html");
504+
await openInBrowser();
505+
// Editing a queued message moves the composer to a draft; the thread stays.
506+
await renderFileFor(threadRef, "index.html", "draft-1" as PanelHost["composerDraftTarget"]);
507+
await settleAsset();
508+
await settleSession();
509+
expect(browsersOf(threadRef).map((surface) => surface.id)).toEqual(["browser:tab-1"]);
510+
});
511+
497512
it("never asks for a browser when the thread was left while the file was prepared", async () => {
498513
const threadRef = refOn("environment-a");
499514
await renderFileFor(threadRef, "index.html");

‎apps/web/src/panels/files/FilesSidePanel.tsx‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,8 +1020,8 @@ export default function FilesSidePanel({
10201020
(path: string) => useRightPanelStore.getState().openFile(threadRef, path),
10211021
[threadRef],
10221022
);
1023-
// Menu and browser actions settle late; they are dropped once the host moves
1024-
// to another thread or draft, never applied to the newer one.
1023+
// Menu actions settle late; they are dropped once the host moves to another
1024+
// thread or draft, never applied to the newer one.
10251025
const isScopeCurrent = useScopeLifetime(
10261026
`${scopedThreadKey(threadRef)}|${
10271027
typeof composerDraftTarget === "string"
@@ -1030,6 +1030,9 @@ export default function FilesSidePanel({
10301030
}`,
10311031
);
10321032
const addToChat = useScopedComposerInsert(isScopeCurrent);
1033+
// Opening a browser belongs to the thread, not the draft: entering or
1034+
// leaving queued-message editing keeps the thread on screen.
1035+
const isThreadVisitCurrent = useScopeLifetime(scopedThreadKey(threadRef));
10331036
const relativePath =
10341037
attachment === undefined ? resolveFilePreviewPath(requestedPath, cwd) : requestedPath;
10351038
const { resolvedTheme } = useTheme();
@@ -1189,15 +1192,19 @@ export default function FilesSidePanel({
11891192
void (async () => {
11901193
const result = await openFileInPreview({
11911194
threadRef,
1192-
isScopeCurrent,
1195+
isScopeCurrent: isThreadVisitCurrent,
11931196
filePath: absolutePath,
11941197
workspaceRoot: cwd,
11951198
httpBaseUrl: environmentHttpBaseUrl,
11961199
createAssetUrl,
11971200
openPreview,
11981201
});
11991202
// Errors are reported only to the visit that started the open.
1200-
if (result._tag === "Success" || isAtomCommandInterrupted(result) || !isScopeCurrent()) {
1203+
if (
1204+
result._tag === "Success" ||
1205+
isAtomCommandInterrupted(result) ||
1206+
!isThreadVisitCurrent()
1207+
) {
12011208
return;
12021209
}
12031210
const error = squashAtomCommandFailure(result);
@@ -1216,7 +1223,7 @@ export default function FilesSidePanel({
12161223
createAssetUrl,
12171224
cwd,
12181225
environmentHttpBaseUrl,
1219-
isScopeCurrent,
1226+
isThreadVisitCurrent,
12201227
openPreview,
12211228
threadRef,
12221229
]);

0 commit comments

Comments
 (0)