Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
Avoid timeline timer rerender commits (#2580)
cursor[bot]2ba58076fa19
diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsxindex dafa8161b..d07aa88ae 100644--- a/apps/web/src/components/chat/MessagesTimeline.tsx+++ b/apps/web/src/components/chat/MessagesTimeline.tsx@@ -520,19 +520,27 @@ function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "workin}// ----------------------------------------------------------------------------// Self-ticking components — bypass LegendList memoisation entirely.-// Each owns a `nowMs` state value consumed in the render output so the-// React Compiler cannot elide the re-render as a no-op.+// Self-ticking labels — update their own text nodes so elapsed-time display+// does not create a React commit every second while a response is streaming.// ---------------------------------------------------------------------------/** Live "Working for Xs" label. */function WorkingTimer({ createdAt }: { createdAt: string }) {- const [nowMs, setNowMs] = useState(() => Date.now());+ const textRef = useRef<HTMLSpanElement>(null);+ const initialText = formatWorkingTimerNow(createdAt);+useEffect(() => {- const id = setInterval(() => setNowMs(Date.now()), 1000);+ const updateText = () => {+ if (textRef.current) {+ textRef.current.textContent = formatWorkingTimerNow(createdAt);+ }+ };+ updateText();+ const id = setInterval(updateText, 1000);return () => clearInterval(id);}, [createdAt]);- return <>{formatWorkingTimer(createdAt, new Date(nowMs).toISOString()) ?? "0s"}</>;++ return <span ref={textRef}>{initialText}</span>;}/** Live timestamp + elapsed duration for a streaming assistant message. */@@ -545,15 +553,28 @@ function LiveMessageMeta({durationStart: string | null | undefined;timestampFormat: TimestampFormat;}) {- const [nowMs, setNowMs] = useState(() => Date.now());+ const textRef = useRef<HTMLSpanElement>(null);+ const initialText = formatLiveMessageMetaNow(createdAt, durationStart, timestampFormat);+useEffect(() => {- const id = setInterval(() => setNowMs(Date.now()), 1000);+ const updateText = () => {+ if (textRef.current) {+ textRef.current.textContent = formatLiveMessageMetaNow(+ createdAt,+ durationStart,+ timestampFormat,+ );+ }+ };+ updateText();+ if (!durationStart) {+ return;+ }+ const id = setInterval(updateText, 1000);return () => clearInterval(id);- }, [durationStart]);- const elapsed = durationStart- ? formatElapsed(durationStart, new Date(nowMs).toISOString())- : null;- return <>{formatMessageMeta(createdAt, elapsed, timestampFormat)}</>;+ }, [createdAt, durationStart, timestampFormat]);++ return <span ref={textRef}>{initialText}</span>;}// ---------------------------------------------------------------------------@@ -860,6 +881,19 @@ function formatWorkingTimer(startIso: string, endIso: string): string | null {return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;}+function formatWorkingTimerNow(startIso: string): string {+ return formatWorkingTimer(startIso, new Date().toISOString()) ?? "0s";+}++function formatLiveMessageMetaNow(+ createdAt: string,+ durationStart: string | null | undefined,+ timestampFormat: TimestampFormat,+): string {+ const elapsed = durationStart ? formatElapsed(durationStart, new Date().toISOString()) : null;+ return formatMessageMeta(createdAt, elapsed, timestampFormat);+}+function formatMessageMeta(createdAt: string,duration: string | null,