Skip to content

Commit 099feb6

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 2ad6f86 commit 099feb6

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
@@ -231,11 +231,15 @@ function composerOf(threadRef: ScopedThreadRef) {
231231
return composers.get(key)!;
232232
}
233233

234-
async function renderFileFor(threadRef: ScopedThreadRef, relativePath: string | null = "src/a.ts") {
234+
async function renderFileFor(
235+
threadRef: ScopedThreadRef,
236+
relativePath: string | null = "src/a.ts",
237+
composerDraftTarget: PanelHost["composerDraftTarget"] = threadRef,
238+
) {
235239
const host: PanelHost = {
236240
threadRef,
237241
visible: true,
238-
composerDraftTarget: threadRef,
242+
composerDraftTarget,
239243
workspaceMutationId: null,
240244
sendAnnotation: () => undefined,
241245
};
@@ -485,6 +489,17 @@ describe("files actions that settle late", () => {
485489
expect(browsersOf(threadRef).map((surface) => surface.id)).toEqual(["browser:tab-1"]);
486490
});
487491

492+
it("still opens a browser after the composer switches drafts in the same thread", async () => {
493+
const threadRef = refOn("environment-a");
494+
await renderFileFor(threadRef, "index.html");
495+
await openInBrowser();
496+
// Editing a queued message moves the composer to a draft; the thread stays.
497+
await renderFileFor(threadRef, "index.html", "draft-1" as PanelHost["composerDraftTarget"]);
498+
await settleAsset();
499+
await settleSession();
500+
expect(browsersOf(threadRef).map((surface) => surface.id)).toEqual(["browser:tab-1"]);
501+
});
502+
488503
it("never asks for a browser when the thread was left while the file was prepared", async () => {
489504
const threadRef = refOn("environment-a");
490505
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
@@ -924,8 +924,8 @@ export default function FilesSidePanel({
924924
(path: string) => useRightPanelStore.getState().openFile(threadRef, path),
925925
[threadRef],
926926
);
927-
// Menu and browser actions settle late; they are dropped once the host moves
928-
// to another thread or draft, never applied to the newer one.
927+
// Menu actions settle late; they are dropped once the host moves to another
928+
// thread or draft, never applied to the newer one.
929929
const isScopeCurrent = useScopeLifetime(
930930
`${scopedThreadKey(threadRef)}|${
931931
typeof composerDraftTarget === "string"
@@ -934,6 +934,9 @@ export default function FilesSidePanel({
934934
}`,
935935
);
936936
const addToChat = useScopedComposerInsert(isScopeCurrent);
937+
// Opening a browser belongs to the thread, not the draft: entering or
938+
// leaving queued-message editing keeps the thread on screen.
939+
const isThreadVisitCurrent = useScopeLifetime(scopedThreadKey(threadRef));
937940
const relativePath =
938941
attachment === undefined ? resolveFilePreviewPath(requestedPath, cwd) : requestedPath;
939942
const { resolvedTheme } = useTheme();
@@ -1087,15 +1090,19 @@ export default function FilesSidePanel({
10871090
void (async () => {
10881091
const result = await openFileInPreview({
10891092
threadRef,
1090-
isScopeCurrent,
1093+
isScopeCurrent: isThreadVisitCurrent,
10911094
filePath: absolutePath,
10921095
workspaceRoot: cwd,
10931096
httpBaseUrl: environmentHttpBaseUrl,
10941097
createAssetUrl,
10951098
openPreview,
10961099
});
10971100
// Errors are reported only to the visit that started the open.
1098-
if (result._tag === "Success" || isAtomCommandInterrupted(result) || !isScopeCurrent()) {
1101+
if (
1102+
result._tag === "Success" ||
1103+
isAtomCommandInterrupted(result) ||
1104+
!isThreadVisitCurrent()
1105+
) {
10991106
return;
11001107
}
11011108
const error = squashAtomCommandFailure(result);
@@ -1112,7 +1119,7 @@ export default function FilesSidePanel({
11121119
createAssetUrl,
11131120
cwd,
11141121
environmentHttpBaseUrl,
1115-
isScopeCurrent,
1122+
isThreadVisitCurrent,
11161123
openPreview,
11171124
threadRef,
11181125
]);

0 commit comments

Comments
 (0)