@devries-cameron20 / t3code-1 / commits / 2ba58076fa
Fork 0

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

Avoid timeline timer rerender commits (#2580)

Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>

cursor[bot] committed May 7, 2026 at 11:54 UTC 2ba58076fa19e11811b021a479400a8810b9930d
1 file changed +47 -13
apps/web/src/components/chat/MessagesTimeline.tsx
+47 -13
@@ -520,19 +520,27 @@ function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "workin
520 }
521
522 // ---------------------------------------------------------------------------
523 -// Self-ticking components — bypass LegendList memoisation entirely.
524 -// Each owns a `nowMs` state value consumed in the render output so the
525 -// React Compiler cannot elide the re-render as a no-op.
523 +// Self-ticking labels — update their own text nodes so elapsed-time display
524 +// does not create a React commit every second while a response is streaming.
525 // ---------------------------------------------------------------------------
526
527 /** Live "Working for Xs" label. */
528 function WorkingTimer({ createdAt }: { createdAt: string }) {
530 - const [nowMs, setNowMs] = useState(() => Date.now());
529 + const textRef = useRef<HTMLSpanElement>(null);
530 + const initialText = formatWorkingTimerNow(createdAt);
531 +
532 useEffect(() => {
532 - const id = setInterval(() => setNowMs(Date.now()), 1000);
533 + const updateText = () => {
534 + if (textRef.current) {
535 + textRef.current.textContent = formatWorkingTimerNow(createdAt);
536 + }
537 + };
538 + updateText();
539 + const id = setInterval(updateText, 1000);
540 return () => clearInterval(id);
541 }, [createdAt]);
535 - return <>{formatWorkingTimer(createdAt, new Date(nowMs).toISOString()) ?? "0s"}</>;
542 +
543 + return <span ref={textRef}>{initialText}</span>;
544 }
545
546 /** Live timestamp + elapsed duration for a streaming assistant message. */
@@ -545,15 +553,28 @@ function LiveMessageMeta({
553 durationStart: string | null | undefined;
554 timestampFormat: TimestampFormat;
555 }) {
548 - const [nowMs, setNowMs] = useState(() => Date.now());
556 + const textRef = useRef<HTMLSpanElement>(null);
557 + const initialText = formatLiveMessageMetaNow(createdAt, durationStart, timestampFormat);
558 +
559 useEffect(() => {
550 - const id = setInterval(() => setNowMs(Date.now()), 1000);
560 + const updateText = () => {
561 + if (textRef.current) {
562 + textRef.current.textContent = formatLiveMessageMetaNow(
563 + createdAt,
564 + durationStart,
565 + timestampFormat,
566 + );
567 + }
568 + };
569 + updateText();
570 + if (!durationStart) {
571 + return;
572 + }
573 + const id = setInterval(updateText, 1000);
574 return () => clearInterval(id);
552 - }, [durationStart]);
553 - const elapsed = durationStart
554 - ? formatElapsed(durationStart, new Date(nowMs).toISOString())
555 - : null;
556 - return <>{formatMessageMeta(createdAt, elapsed, timestampFormat)}</>;
575 + }, [createdAt, durationStart, timestampFormat]);
576 +
577 + return <span ref={textRef}>{initialText}</span>;
578 }
579
580 // ---------------------------------------------------------------------------
@@ -860,6 +881,19 @@ function formatWorkingTimer(startIso: string, endIso: string): string | null {
881 return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;
882 }
883
884 +function formatWorkingTimerNow(startIso: string): string {
885 + return formatWorkingTimer(startIso, new Date().toISOString()) ?? "0s";
886 +}
887 +
888 +function formatLiveMessageMetaNow(
889 + createdAt: string,
890 + durationStart: string | null | undefined,
891 + timestampFormat: TimestampFormat,
892 +): string {
893 + const elapsed = durationStart ? formatElapsed(durationStart, new Date().toISOString()) : null;
894 + return formatMessageMeta(createdAt, elapsed, timestampFormat);
895 +}
896 +
897 function formatMessageMeta(
898 createdAt: string,
899 duration: string | null,