Skip to content

Commit ee3081e

Browse files
only21milclaude
andcommitted
fix(web): read live route send state in the restore-prompt toast
The "Restore prompt" toast stays open after its send settles. Once the route goes idle its send state is dropped, so the toast's in-flight check read the dropped object and missed a newer send on the same draft. Look up the route's current state instead, as the shared object did before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 71b83c9 commit ee3081e

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎apps/web/src/components/ChatView.logic.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
releaseDraftSendStateIfIdle,
1212
rememberCheckoutIsRepo,
1313
retainDraftSendState,
14+
routeSendInFlight,
1415
threadShellHasStarted,
1516
} from "./ChatView.logic";
1617
import {
@@ -2070,6 +2071,21 @@ describe("route send state", () => {
20702071
expect(draftSendState("route-strict")).toBe(state);
20712072
remount();
20722073
});
2074+
2075+
it("reports a newer send after the earlier state was released", () => {
2076+
const first = mountRoute("route-restore");
2077+
first.state.sendInFlight.current = true;
2078+
first.unmount();
2079+
first.state.sendInFlight.current = false;
2080+
2081+
const second = mountRoute("route-restore");
2082+
second.state.sendInFlight.current = true;
2083+
expect(second.state).not.toBe(first.state);
2084+
expect(routeSendInFlight("route-restore")).toBe(true);
2085+
second.state.sendInFlight.current = false;
2086+
expect(routeSendInFlight("route-restore")).toBe(false);
2087+
second.unmount();
2088+
});
20732089
});
20742090

20752091
describe("threadShellHasStarted", () => {

‎apps/web/src/components/ChatView.logic.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,11 @@ export function releaseDraftSendStateIfIdle(routeKey: string, state: DraftSendSt
10131013
}
10141014
}
10151015

1016+
/** Whether the route's current send state has a send in flight. Never creates an entry. */
1017+
export function routeSendInFlight(routeKey: string): boolean {
1018+
return draftSendStateByRouteKey.get(routeKey)?.sendInFlight.current === true;
1019+
}
1020+
10161021
export function countDraftSendStatesForTests(): number {
10171022
return draftSendStateByRouteKey.size;
10181023
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
releaseDraftSendStateIfIdle,
2626
rememberCheckoutIsRepo,
2727
retainDraftSendState,
28+
routeSendInFlight,
2829
} from "./ChatView.logic";
2930
import { useLoadBalancedEnvironment } from "../hooks/useLoadBalancedEnvironment";
3031
import { useLogicalProjectEnvironments } from "../hooks/useLogicalProjectEnvironments";
@@ -7000,7 +7001,7 @@ export default function ChatView(props: ChatViewProps) {
70007001
if (
70017002
!draftId ||
70027003
!useComposerDraftStore.getState().getDraftSession(draftId) ||
7003-
sendInFlightRef.current ||
7004+
routeSendInFlight(routeThreadKey) ||
70047005
composerDraftHasUserContent(
70057006
useComposerDraftStore.getState().getComposerDraft(composerDraftTarget),
70067007
)

0 commit comments

Comments
 (0)