The best way to control Claude Code, Codex and more from any computer or phone
fix(web): opening a deleted thread from the timeline stays on the current thread (#20747)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
voida6 committed
Oct 20, 2026 at 15:19 UTC
c768c6dfbf53aee3ead84b298be8aaaf906eb796
1 file changed
+29
-4
apps/web/src/components/ChatView.tsx
+29
-4
@@ -158,7 +158,7 @@ import {
158
useState,
159
} from "react";
160
import { flushSync } from "react-dom";
161
-import { useLocation, useNavigate } from "@tanstack/react-router";
161
+import { useLocation, useNavigate, useRouter } from "@tanstack/react-router";
162
import { assistantCitationFromLocation } from "../lib/assistantCitationNavigation";
163
import { isMacPlatform } from "../lib/utils";
164
import type { AssistantCitationSourceAnchor } from "~/lib/assistantTextSelection";
@@ -391,9 +391,10 @@ import {
391
useThreadRefs,
392
useThreadVisibleTurnItems,
393
useThreadCheckpointSummaries,
394
+ readThreadShell,
395
waitForThreadShell,
396
} from "../state/entities";
396
-import { useEnvironmentShellHasSnapshot } from "../state/shell";
397
+import { environmentShell, useEnvironmentShellHasSnapshot } from "../state/shell";
398
import { ChatComposer, type ChatComposerHandle } from "./chat/ChatComposer";
399
import { createPageScrollController, type PageScrollKey } from "./chat/pageScrollController";
400
import { isTimelineScrollTarget } from "./chat/timelineScrollTarget";
@@ -574,6 +575,7 @@ const EMPTY_FEEDBACK_SUBMISSIONS: ReadonlyArray<CodexFeedbackSubmission> = [];
575
// second, and every server-side visit is a full command dispatch plus a
576
// broadcast to all shell subscribers.
577
const VISIT_DISPATCH_THROTTLE_MS = 10_000;
578
+const RELATED_THREAD_SHELL_WAIT_MS = 1_000;
579
const EMPTY_PROVIDER_SKILLS: ServerProvider["skills"] = [];
580
const EMPTY_AUTO_UPDATE_ENVIRONMENTS: ReadonlyArray<EnvironmentPresentation> = [];
581
function useDraftHeroLayoutTransition(
@@ -1198,6 +1200,7 @@ export default function ChatView(props: ChatViewProps) {
1200
);
1201
const timestampFormat = settings.timestampFormat;
1202
const navigate = useNavigate();
1203
+ const router = useRouter();
1204
// Selects primitives: an object here is new on every router store update, which
1205
// re-renders ChatView on unrelated navigation state changes.
1206
const citationHref = useLocation({ select: (location) => location.href });
@@ -5044,10 +5047,32 @@ export default function ChatView(props: ChatViewProps) {
5047
}
5048
};
5049
const handleStopBackgroundWorkStable = useStableCallback(handleStopBackgroundWork);
5047
- const onOpenRelatedThread = (threadId: ThreadId) => {
5050
+ const openRelatedThreadGenerationRef = useRef(0);
5051
+ const onOpenRelatedThread = async (threadId: ThreadId) => {
5052
+ const generation = ++openRelatedThreadGenerationRef.current;
5053
+ const threadRef = scopeThreadRef(environmentId, threadId);
5054
+ const isEnvironmentLive = () =>
5055
+ appAtomRegistry.get(environmentShell.stateValueAtom(environmentId)).status === "live";
5056
+ // A just-launched child can reach this timeline before its shell syncs.
5057
+ if (isEnvironmentLive() && readThreadShell(threadRef) === null) {
5058
+ const location = router.latestLocation;
5059
+ await waitForThreadShell(threadRef, RELATED_THREAD_SHELL_WAIT_MS);
5060
+ if (
5061
+ generation !== openRelatedThreadGenerationRef.current ||
5062
+ currentRouteThreadKeyRef.current !== routeThreadKey ||
5063
+ router.latestLocation !== location
5064
+ ) {
5065
+ return;
5066
+ }
5067
+ }
5068
+ const shell = readThreadShell(threadRef);
5069
+ if (shell === null ? isEnvironmentLive() : shell.deletedAt != null) {
5070
+ toastManager.add({ type: "info", title: "This thread is no longer available" });
5071
+ return;
5072
+ }
5073
void navigate({
5074
to: "/$environmentId/$threadId",
5050
- params: buildThreadRouteParams(scopeThreadRef(environmentId, threadId)),
5075
+ params: buildThreadRouteParams(threadRef),
5076
});
5077
};
5078
const onOpenRelatedThreadStable = useStableCallback(onOpenRelatedThread);