Skip to content

Commit 3f4ca0f

Browse files
fix(web): a draft closed mid machine switch no longer rewrites that draft
Since #20418 dropped the effect cleanup, a draft view that unmounted while openScratchProject was pending kept its request alive, so the completion still retargeted the draft's machine and project. A layout-effect cleanup keyed on the draft/project scope now abandons the in-flight request. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f5cb328 commit 3f4ca0f

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,6 +3276,15 @@ export default function ChatView(props: ChatViewProps) {
32763276
useLayoutEffect(() => {
32773277
environmentChangeScopeRef.current = environmentChangeScope;
32783278
});
3279+
// Leaving the scope, or unmounting, abandons a change still in flight.
3280+
useLayoutEffect(
3281+
() => () => {
3282+
if (environmentChangeRef.current?.scope === environmentChangeScope) {
3283+
environmentChangeRef.current = null;
3284+
}
3285+
},
3286+
[environmentChangeScope],
3287+
);
32793288
const readPendingEnvironmentChange = () => {
32803289
const pending = environmentChangeRef.current;
32813290
return pending !== null && pending.scope === environmentChangeScopeRef.current ? pending : null;

0 commit comments

Comments
 (0)