Skip to content
TypeScript

fix(web): stop crashing the native React Compiler on ChatView (#20340)

Julius Marminge9ef927496573
diff --git a/apps/web/src/components/ChatView.logic.test.ts b/apps/web/src/components/ChatView.logic.test.ts
index fdd16a34e53..45f382f7279 100644
--- a/apps/web/src/components/ChatView.logic.test.ts
+++ b/apps/web/src/components/ChatView.logic.test.ts
@@ -1,5 +1,6 @@
import {
findRecordedWorktreeSetup,
+ isThreadWokeUnseen,
mergeDirectPreviewAnnotation,
resolveVisibleWorktreeSetup,
} from "./ChatView.logic";
@@ -2234,3 +2235,29 @@ describe("mergeDirectPreviewAnnotation", () => {
expect(result.previewAnnotations).toBe(existing);
});
});
+
+describe("isThreadWokeUnseen", () => {
+ const base = {
+ wokeAt: "2026-10-16T10:00:00.000Z",
+ settled: false,
+ lastVisitedAt: null,
+ latestRunCompletedAt: null,
+ };
+
+ it("shows a wake the user has not seen", () => {
+ expect(isThreadWokeUnseen({ ...base, lastVisitedAt: "2026-10-16T09:00:00.000Z" })).toBe(true);
+ expect(isThreadWokeUnseen(base)).toBe(true);
+ });
+
+ it("hides a wake seen by a later visit or a later completed run", () => {
+ expect(isThreadWokeUnseen({ ...base, lastVisitedAt: "2026-10-16T11:00:00.000Z" })).toBe(false);
+ expect(isThreadWokeUnseen({ ...base, latestRunCompletedAt: "2026-10-16T11:00:00.000Z" })).toBe(
+ false,
+ );
+ });
+
+ it("hides settled threads and unparseable wake times", () => {
+ expect(isThreadWokeUnseen({ ...base, settled: true })).toBe(false);
+ expect(isThreadWokeUnseen({ ...base, wokeAt: "not a date" })).toBe(false);
+ });
+});
diff --git a/apps/web/src/components/ChatView.logic.ts b/apps/web/src/components/ChatView.logic.ts
index 7765ad6edbe..0e200d0cd92 100644
--- a/apps/web/src/components/ChatView.logic.ts
+++ b/apps/web/src/components/ChatView.logic.ts
@@ -1339,3 +1339,22 @@ export function mergeDirectPreviewAnnotation(input: {
];
return { images, previewAnnotations };
}
+
+/**
+ * Whether a woken thread woke after the user last saw it. A run that completed
+ * after the last visit counts as seeing it, since the user watched it finish.
+ */
+export function isThreadWokeUnseen(input: {
+ readonly wokeAt: string | null;
+ readonly settled: boolean;
+ readonly lastVisitedAt: string | null | undefined;
+ readonly latestRunCompletedAt: string | null;
+}): boolean {
+ if (input.wokeAt === null || input.settled) return false;
+ const wokeAtMs = Date.parse(input.wokeAt);
+ if (Number.isNaN(wokeAtMs)) return false;
+ const seenAt = [input.lastVisitedAt, input.latestRunCompletedAt]
+ .map((value) => (value ? Date.parse(value) : NaN))
+ .filter((ms) => !Number.isNaN(ms));
+ return seenAt.every((ms) => ms < wokeAtMs);
+}
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index 7e49209c206..52e043eb90c 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -2,6 +2,7 @@ import { ThreadFind, ThreadFindCanvas, type ThreadFindControls } from "./chat/Th
import { THREAD_FIND_BAR_RESERVED_HEIGHT } from "./chat/ThreadFindBar";
import { usageLimitRecoveryBannerItem } from "./chat/UsageLimitRecoveryBanner";
import {
+ isThreadWokeUnseen,
mergeDirectPreviewAnnotation,
resolveBackgroundDraftWorkspaceOptions,
resolveDraftHeroState,
@@ -5267,26 +5268,12 @@ export default function ChatView(props: ChatViewProps) {
activeThreadShell?.lastVisitedAt,
activeThreadLocalVisitedAt,
);
- const activeThreadWokeVisible = useMemo(() => {
- if (activeThreadWokeAt === null) return false;
- if (activeThreadShell?.settledOverride === "settled") return false;
- const wokeAtMs = Date.parse(activeThreadWokeAt);
- if (Number.isNaN(wokeAtMs)) return false;
- const storedVisitMs = activeThreadLastVisitedAt ? Date.parse(activeThreadLastVisitedAt) : NaN;
- const completedAtMs = activeLatestRun?.completedAt
- ? Date.parse(activeLatestRun.completedAt)
- : NaN;
- const lastVisitedMs = Math.max(
- Number.isNaN(storedVisitMs) ? -Infinity : storedVisitMs,
- Number.isNaN(completedAtMs) ? -Infinity : completedAtMs,
- );
- return lastVisitedMs < wokeAtMs;
- }, [
- activeLatestRun?.completedAt,
- activeThreadLastVisitedAt,
- activeThreadShell,
- activeThreadWokeAt,
- ]);
+ const activeThreadWokeVisible = isThreadWokeUnseen({
+ wokeAt: activeThreadWokeAt,
+ settled: activeThreadShell?.settledOverride === "settled",
+ lastVisitedAt: activeThreadLastVisitedAt,
+ latestRunCompletedAt: activeLatestRun?.completedAt ?? null,
+ });
const activeThreadSettled =
supportsSettlement && activeThreadShell?.settledOverride === "settled";
const unsettleThreadMutation = useOrchestrationCommand(threadEnvironment.unsettle, {