Skip to content
TypeScript

fix(web): a draft closed mid machine switch no longer rewrites that draft (#20442)

Julius Marminge52cd9c5a19f8
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index c6b4d37dfa6..2a169b14aee 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -3276,6 +3276,15 @@ export default function ChatView(props: ChatViewProps) {
useLayoutEffect(() => {
environmentChangeScopeRef.current = environmentChangeScope;
});
+ // Leaving the scope, or unmounting, abandons a change still in flight.
+ useLayoutEffect(
+ () => () => {
+ if (environmentChangeRef.current?.scope === environmentChangeScope) {
+ environmentChangeRef.current = null;
+ }
+ },
+ [environmentChangeScope],
+ );
const readPendingEnvironmentChange = () => {
const pending = environmentChangeRef.current;
return pending !== null && pending.scope === environmentChangeScopeRef.current ? pending : null;