@devries-cameron20 / t3code-1 / commits / 542287245d
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): an abandoned machine switch still clears its busy state (#20519)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 16, 2026 at 19:04 UTC 542287245dc93186a0d11f347e786d4264d547df
1 file changed +11 -10
apps/web/src/components/ChatView.tsx
+11 -10
@@ -3298,10 +3298,13 @@ export default function ChatView(props: ChatViewProps) {
3298 const pending = environmentChangeRef.current;
3299 return pending !== null && pending.scope === environmentChangeScopeRef.current ? pending : null;
3300 };
3301 - const [environmentChangingScope, setEnvironmentChangingScope] = useState<string | null>(null);
3302 - const isEnvironmentChanging = environmentChangingScope === environmentChangeScope;
3303 - const setIsEnvironmentChanging = (changing: boolean) =>
3304 - setEnvironmentChangingScope(changing ? environmentChangeScope : null);
3301 + // The busy state belongs to the request that set it, so an older request settling late
3302 + // (abandoned, or superseded by a newer switch) can never clear a newer one's.
3303 + const [busyEnvironmentChange, setBusyEnvironmentChange] = useState<{
3304 + readonly environmentId: EnvironmentId;
3305 + readonly scope: string;
3306 + } | null>(null);
3307 + const isEnvironmentChanging = busyEnvironmentChange?.scope === environmentChangeScope;
3308
3309 const onEnvironmentChange = (nextEnvironmentId: EnvironmentId) => {
3310 if (envLocked || !draftId || sendInFlightRef.current) return;
@@ -3313,7 +3316,7 @@ export default function ChatView(props: ChatViewProps) {
3316 if (!target) return;
3317 const request = { environmentId: target.environmentId, scope: environmentChangeScope };
3318 environmentChangeRef.current = request;
3316 - setIsEnvironmentChanging(false);
3319 + setBusyEnvironmentChange(null);
3320 const retarget = (project: (typeof allProjects)[number]) => {
3321 const currentDraft = getDraftSession(draftId);
3322 if (
@@ -3343,10 +3346,8 @@ export default function ChatView(props: ChatViewProps) {
3346 }
3347 };
3348 const finish = () => {
3346 - if (environmentChangeRef.current === request) {
3347 - environmentChangeRef.current = null;
3348 - setIsEnvironmentChanging(false);
3349 - }
3349 + if (environmentChangeRef.current === request) environmentChangeRef.current = null;
3350 + setBusyEnvironmentChange((busy) => (busy === request ? null : busy));
3351 };
3352 if (target.projectId !== null) {
3353 const project = allProjects.find(
@@ -3357,7 +3358,7 @@ export default function ChatView(props: ChatViewProps) {
3358 finish();
3359 return;
3360 }
3360 - setIsEnvironmentChanging(true);
3361 + setBusyEnvironmentChange(request);
3362 void openScratchProject(target.environmentId, "Could not switch machine")
3363 .then((project) => {
3364 if (project) retarget(project);