Skip to content

Commit 8fcde24

Browse files
fix(web): a promoted draft keeps its redirect while Settings is open
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c7e122e commit 8fcde24

3 files changed

Lines changed: 44 additions & 10 deletions

File tree

‎apps/web/src/appInit.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { startKeybindingsUpdateToasts } from "./components/KeybindingsUpdateToas
1515
import { startLegacyThreadMigrationToast } from "./components/LegacyThreadMigrationToast";
1616
import { startPermissionUpdateNotices } from "./components/PermissionUpdateNotice";
1717
import { startAgentOpenedPreviews } from "./components/preview/agentOpenedPreviews";
18-
import { startMainAppLocationTracking } from "./components/sidebar/mainAppLocation";
18+
import { isAppModalPage, startMainAppLocationTracking } from "./components/sidebar/mainAppLocation";
1919
import { startDesktopUpdateLaunchNotice } from "./components/sidebar/updateEverythingRun";
2020
import { startSlowRpcRequestToasts } from "./components/SlowRpcRequestToastCoordinator";
2121
import { startThreadNotifications } from "./components/ThreadNotificationCoordinator";
@@ -154,7 +154,10 @@ function startDraftThreadPromotion(router: AppRouter): void {
154154
});
155155
router.subscribe("onResolved", () => {
156156
const target = resolveThreadRouteTarget(router.state.matches.at(-1)?.params ?? {});
157-
useComposerDraftStore.getState().retainPromotedDraftRedirectsForRoute(target);
157+
useComposerDraftStore.getState().retainPromotedDraftRedirectsForRoute({
158+
modalPage: isAppModalPage(router.state.location.pathname),
159+
target,
160+
});
158161
});
159162
}
160163

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,13 @@ describe("composerDraftStore draft promotion", () => {
13821382
backgroundSubmissionPending: false,
13831383
}),
13841384
).toBeNull();
1385+
expect(
1386+
resolveDraftPromotionNavigationTarget({
1387+
serverThreadRef: threadRef,
1388+
serverThread: { latestRun: null, latestUserMessageAt: null },
1389+
backgroundSubmissionPending: false,
1390+
}),
1391+
).toBeNull();
13851392
const persisted = { latestRun: preparingRun, latestUserMessageAt: "2026-03-29T00:00:00.000Z" };
13861393
expect(
13871394
resolveDraftPromotionNavigationTarget({
@@ -1430,16 +1437,35 @@ describe("composerDraftStore draft promotion", () => {
14301437
useComposerDraftStore.setState({ promotedDraftRedirects: { [draftId]: threadRef } });
14311438
const store = useComposerDraftStore.getState();
14321439

1433-
store.retainPromotedDraftRedirectsForRoute({ kind: "draft", draftId });
1434-
store.retainPromotedDraftRedirectsForRoute({ kind: "server", threadRef });
1440+
store.retainPromotedDraftRedirectsForRoute({
1441+
modalPage: false,
1442+
target: { kind: "draft", draftId },
1443+
});
1444+
store.retainPromotedDraftRedirectsForRoute({
1445+
modalPage: false,
1446+
target: { kind: "server", threadRef },
1447+
});
14351448
expect(useComposerDraftStore.getState().getPromotedDraftIdByRef(threadRef)).toBe(draftId);
14361449

1437-
store.retainPromotedDraftRedirectsForRoute({ kind: "server", threadRef: otherRef });
1450+
store.retainPromotedDraftRedirectsForRoute({
1451+
modalPage: false,
1452+
target: { kind: "server", threadRef: otherRef },
1453+
});
14381454
expect(useComposerDraftStore.getState().promotedDraftRedirects).toEqual({});
14391455
// A later visit renders the shared unkeyed ChatView.
14401456
expect(useComposerDraftStore.getState().getPromotedDraftIdByRef(threadRef)).toBeNull();
14411457
});
14421458

1459+
it("keeps a promotion redirect while Settings or Usage is open over its draft", () => {
1460+
useComposerDraftStore.setState({ promotedDraftRedirects: { [draftId]: threadRef } });
1461+
const store = useComposerDraftStore.getState();
1462+
1463+
// Each settings section is its own route with no thread target; closing returns to the draft.
1464+
store.retainPromotedDraftRedirectsForRoute({ modalPage: true, target: null });
1465+
store.retainPromotedDraftRedirectsForRoute({ modalPage: true, target: null });
1466+
expect(useComposerDraftStore.getState().getPromotedDraftRedirect(draftId)).toEqual(threadRef);
1467+
});
1468+
14431469
it("holds a background submission on its draft until the send settles", async () => {
14441470
const h = draftPromotionHarness();
14451471
const store = useComposerDraftStore.getState();

‎apps/web/src/composerDraftStore.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,10 @@ interface ComposerDraftStoreState {
440440
getDraftIdByRef: (threadRef: ScopedThreadRef) => DraftId | null;
441441
getPromotedDraftRedirect: (draftId: DraftId) => ScopedThreadRef | null;
442442
getPromotedDraftIdByRef: (threadRef: ScopedThreadRef) => DraftId | null;
443-
retainPromotedDraftRedirectsForRoute: (route: ThreadRouteTarget | null) => void;
443+
retainPromotedDraftRedirectsForRoute: (route: {
444+
modalPage: boolean;
445+
target: ThreadRouteTarget | null;
446+
}) => void;
444447
getDraftThreadByRef: (threadRef: ScopedThreadRef) => DraftThreadState | null;
445448
getDraftThread: (threadRef: ComposerThreadTarget) => DraftThreadState | null;
446449
listDraftThreadKeys: () => string[];
@@ -2493,13 +2496,15 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
24932496
}
24942497
return null;
24952498
},
2496-
retainPromotedDraftRedirectsForRoute: (route) => {
2499+
retainPromotedDraftRedirectsForRoute: ({ modalPage, target }) => {
2500+
// Settings and Usage render over the draft and close back to it, so it still needs its redirect.
2501+
if (modalPage) return;
24972502
set((state) => {
24982503
const entries = Object.entries(state.promotedDraftRedirects);
24992504
const retained = entries.filter(([draftId, promotedTo]) =>
2500-
route?.kind === "draft"
2501-
? route.draftId === draftId
2502-
: route?.kind === "server" && scopedThreadRefsEqual(promotedTo, route.threadRef),
2505+
target?.kind === "draft"
2506+
? target.draftId === draftId
2507+
: target?.kind === "server" && scopedThreadRefsEqual(promotedTo, target.threadRef),
25032508
);
25042509
return retained.length === entries.length
25052510
? state

0 commit comments

Comments
 (0)