From e07e4026c1d7588bc48356ab2b03886c024432a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BC=D0=B0=D1=80=D0=BE=D0=B2=20=D0=91=D0=B0=D0=B3?= =?UTF-8?q?=D0=B0=D1=83=D1=82=D0=B4=D0=B8=D0=BD?= Date: Sun, 15 Mar 2026 08:09:18 +0300 Subject: [PATCH] fix(web): replace hasOpenedDiff useState/useEffect latch with useRef setState inside useEffect schedules an extra render. The value only gates rendering, never drives it, so a ref is the right tool. --- apps/web/src/routes/_chat.$threadId.tsx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/web/src/routes/_chat.$threadId.tsx b/apps/web/src/routes/_chat.$threadId.tsx index 8e7a5d3ba..33f3ed31e 100644 --- a/apps/web/src/routes/_chat.$threadId.tsx +++ b/apps/web/src/routes/_chat.$threadId.tsx @@ -1,6 +1,6 @@ import { ThreadId } from "@t3tools/contracts"; import { createFileRoute, retainSearchParams, useNavigate } from "@tanstack/react-router"; -import { Suspense, lazy, type ReactNode, useCallback, useEffect, useState } from "react"; +import { Suspense, lazy, type ReactNode, useCallback, useEffect, useRef } from "react"; import ChatView from "../components/ChatView"; import { DiffWorkerPoolProvider } from "../components/DiffWorkerPoolProvider"; @@ -176,7 +176,7 @@ function ChatThreadRouteView() { const shouldUseDiffSheet = useMediaQuery(DIFF_INLINE_LAYOUT_MEDIA_QUERY); // TanStack Router keeps active route components mounted across param-only navigations // unless remountDeps are configured, so this stays warm across thread switches. - const [hasOpenedDiff, setHasOpenedDiff] = useState(diffOpen); + const hasOpenedDiffRef = useRef(diffOpen); const closeDiff = useCallback(() => { void navigate({ to: "/$threadId", @@ -195,11 +195,7 @@ function ChatThreadRouteView() { }); }, [navigate, threadId]); - useEffect(() => { - if (diffOpen) { - setHasOpenedDiff(true); - } - }, [diffOpen]); + if (diffOpen) hasOpenedDiffRef.current = true; useEffect(() => { if (!threadsHydrated) { @@ -216,7 +212,7 @@ function ChatThreadRouteView() { return null; } - const shouldRenderDiffContent = diffOpen || hasOpenedDiff; + const shouldRenderDiffContent = diffOpen || hasOpenedDiffRef.current; if (!shouldUseDiffSheet) { return (