Skip to content

Commit c0dec60

Browse files
fix(web): a thread opened from the sidebar mid-handoff keeps its draft's ChatView
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ead5049 commit c0dec60

2 files changed

Lines changed: 7 additions & 25 deletions

File tree

‎apps/web/src/components/ThreadRouteView.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export function ThreadRouteView({
4646
const draftThread = useComposerDraftStore((store) =>
4747
serverThreadRef ? store.getDraftThreadByRef(serverThreadRef) : null,
4848
);
49+
// Reached from the sidebar before finalize, the thread still has its draft.
50+
const serverThreadDraftId = useComposerDraftStore((store) =>
51+
serverThreadRef ? store.getDraftIdByRef(serverThreadRef) : null,
52+
);
4953
// The ChatView that carried a draft keeps its key through the redirect to its thread, and only
5054
// until the route leaves that thread, so later visits reuse the shared unkeyed ChatView.
5155
const [handoffKey, setHandoffKey] = useState<{ threadKey: string; key: string } | null>(null);
@@ -56,7 +60,9 @@ export function ThreadRouteView({
5660
: { threadKey: scopedThreadKey(draftRedirect), key: draftId }
5761
: serverThreadRef && handoffKey?.threadKey === scopedThreadKey(serverThreadRef)
5862
? handoffKey
59-
: null;
63+
: serverThreadRef && serverThreadDraftId
64+
? { threadKey: scopedThreadKey(serverThreadRef), key: serverThreadDraftId }
65+
: null;
6066
if (nextHandoffKey !== handoffKey) {
6167
setHandoffKey(nextHandoffKey);
6268
}

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,30 +1451,6 @@ describe("composerDraftStore draft promotion", () => {
14511451
expect(useComposerDraftStore.getState().getDraftSession(draftId)).toBeNull();
14521452
});
14531453

1454-
it("keeps the redirect of a draft finalized while another route was open", async () => {
1455-
// A failed send restored onto its existing thread, or a background send, finalizes while the
1456-
// user is elsewhere; "Open draft" or Back to /draft/<id> later must still reach the thread.
1457-
const h = draftPromotionHarness();
1458-
const store = useComposerDraftStore.getState();
1459-
store.setProjectDraftThreadId(projectRef, draftId, { threadId });
1460-
h.arrive(threadRef, {
1461-
latestRun: preparingRun,
1462-
latestUserMessageAt: "2026-03-29T00:00:00.000Z",
1463-
});
1464-
await waitForDraftHeroTransition();
1465-
expect(useComposerDraftStore.getState().getDraftSession(draftId)).toBeNull();
1466-
1467-
const laterDraftId = DraftId.make("draft-later");
1468-
const laterThreadId = ThreadId.make("thread-later");
1469-
store.setProjectDraftThreadId(projectRef, laterDraftId, { threadId: laterThreadId });
1470-
h.arrive(scopeThreadRef(TEST_ENVIRONMENT_ID, laterThreadId), {
1471-
latestRun: preparingRun,
1472-
latestUserMessageAt: "2026-03-29T00:00:00.000Z",
1473-
});
1474-
await waitForDraftHeroTransition();
1475-
expect(useComposerDraftStore.getState().getPromotedDraftRedirect(draftId)).toEqual(threadRef);
1476-
});
1477-
14781454
it("does not finalize a draft whose send failed and was restored", async () => {
14791455
const h = draftPromotionHarness();
14801456
const store = useComposerDraftStore.getState();

0 commit comments

Comments
 (0)