@devries-cameron20 / t3code Mirror · read-only / commits / 130f4a2457
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 05:30 UTC

perf(web): a minute tick no longer re-renders every sidebar thread row (#20814)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 17, 2026 at 02:08 UTC 130f4a2457172eb62bfd53ae9f5fa16cae8be5d5
2 files changed +64 -60
apps/web/src/components/Sidebar.tsx
+57 -56
@@ -758,14 +758,19 @@ function compactSidebarTimeLabel(label: string): string {
758 return label.endsWith(" ago") ? label.slice(0, -4) : label;
759 }
760
761 -function threadTimeLabel(thread: SidebarThreadSummary): string {
762 - const timestamp = thread.latestUserMessageAt ?? thread.updatedAt;
763 - return compactSidebarTimeLabel(formatRelativeTimeLabel(timestamp));
761 +// Subscribes to the minute tick itself, so only the label re-renders each
762 +// minute. The minute is passed as the clock so it is the formatter's input.
763 +function RelativeTimeLabel(props: { timestamp: string | null }) {
764 + const nowMinute = useNowMinute();
765 + return props.timestamp === null
766 + ? null
767 + : compactSidebarTimeLabel(
768 + formatRelativeTimeLabel(props.timestamp, Date.parse(`${nowMinute}:00.000Z`)),
769 + );
770 }
771
766 -function settledTimeLabel(thread: SidebarThreadSummary): string {
767 - const timestamp = resolveSettledThreadTimestamp(thread);
768 - return timestamp === null ? "" : compactSidebarTimeLabel(formatRelativeTimeLabel(timestamp));
772 +function threadTimeTimestamp(thread: SidebarThreadSummary): string {
773 + return thread.latestUserMessageAt ?? thread.updatedAt;
774 }
775
776 function JumpHintBadge(props: { label: string }) {
@@ -1052,18 +1057,25 @@ type SortableThreadRowBag = Pick<
1057 const SIDEBAR_SORTABLE_DRAG_DISABLED = { draggable: true } as const;
1058 const SIDEBAR_SORTABLE_DRAG_ENABLED = { draggable: false } as const;
1059
1055 -function SortableThreadRow(props: {
1056 - id: string;
1057 - disabled: boolean;
1058 - contextDrag: boolean;
1059 - environmentId: EnvironmentId;
1060 - children: (bag: SortableThreadRowBag) => ReactNode;
1061 -}) {
1062 - const canOperateThread = useEnvironmentScope(props.environmentId, AuthOrchestrationOperateScope);
1060 +// Takes the row's props rather than a render function: a closure from the
1061 +// sidebar body is new on every sidebar render, which rebuilt the bag and
1062 +// re-rendered every memoized row with it.
1063 +function SortableThreadRow(
1064 + props: Omit<SidebarThreadRowProps, "sortable"> & {
1065 + sortableId: string;
1066 + sortableDisabled: boolean;
1067 + contextDrag: boolean;
1068 + },
1069 +) {
1070 + const { sortableId, sortableDisabled, contextDrag, ...rowProps } = props;
1071 + const canOperateThread = useEnvironmentScope(
1072 + rowProps.thread.environmentId,
1073 + AuthOrchestrationOperateScope,
1074 + );
1075 const { listeners, setNodeRef, transform, transition, isDragging } = useSortable({
1064 - id: props.id,
1076 + id: sortableId,
1077 disabled:
1066 - props.disabled || !canOperateThread
1078 + sortableDisabled || !canOperateThread
1079 ? SIDEBAR_SORTABLE_DRAG_DISABLED
1080 : SIDEBAR_SORTABLE_DRAG_ENABLED,
1081 animateLayoutChanges: animateSidebarLayoutChanges,
@@ -1073,11 +1085,12 @@ function SortableThreadRow(props: {
1085 const bag = {
1086 listeners,
1087 setNodeRef,
1076 - transform: props.contextDrag ? null : transform,
1077 - transition: props.contextDrag && isDragging ? "transform 150ms ease-out" : transition,
1078 - isDragging: isDragging && !props.contextDrag,
1088 + transform: contextDrag ? null : transform,
1089 + transition: contextDrag && isDragging ? "transform 150ms ease-out" : transition,
1090 + isDragging: isDragging && !contextDrag,
1091 };
1080 - return props.children(bag);
1092 + // Keyed by variant so a card/slim switch remounts the row.
1093 + return <SidebarThreadRow key={rowProps.variant} {...rowProps} sortable={bag} />;
1094 }
1095
1096 const draftSurfaceClassName = "bg-warning/4 hover:bg-warning/8";
@@ -1446,7 +1459,7 @@ const dropVerbBadge: Record<SidebarDropVerb, ReactNode> = {
1459 ),
1460 };
1461
1449 -const SidebarThreadRow = memo(function SidebarThreadRow(props: {
1462 +type SidebarThreadRowProps = {
1463 thread: SidebarThreadSummary;
1464 variant: "card" | "slim";
1465 variantAction: SidebarSweepAction;
@@ -1492,7 +1505,9 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
1505 onUnpin: (threadRef: ScopedThreadRef) => void;
1506 onAcknowledgeWoke: (threadRef: ScopedThreadRef, visitedAt: string) => void;
1507 onFileDropThreads?: ((threadRef: ScopedThreadRef, files: File[]) => void) | undefined;
1495 -}) {
1508 +};
1509 +
1510 +const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowProps) {
1511 const {
1512 isRenaming,
1513 onCancelRename,
@@ -2068,9 +2083,13 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
2083 </Tooltip>
2084 ) : (
2085 <span className="text-xs">
2071 - {variantAction === "unsettle"
2072 - ? settledTimeLabel(thread)
2073 - : threadTimeLabel(thread)}
2086 + <RelativeTimeLabel
2087 + timestamp={
2088 + variantAction === "unsettle"
2089 + ? resolveSettledThreadTimestamp(thread)
2090 + : threadTimeTimestamp(thread)
2091 + }
2092 + />
2093 </span>
2094 )}
2095 </span>
@@ -2260,7 +2279,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
2279 </span>
2280 )
2281 ) : (
2263 - threadTimeLabel(thread)
2282 + <RelativeTimeLabel timestamp={threadTimeTimestamp(thread)} />
2283 )}
2284 </span>
2285 {props.settlementSupported || showSnoozeButton || hasUnsentDraft ? (
@@ -2544,7 +2563,7 @@ const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: {
2563 />
2564 </span>
2565 <span className="w-8 shrink-0 text-right text-xs text-muted-foreground/55 tabular-nums">
2547 - {threadTimeLabel(thread)}
2566 + <RelativeTimeLabel timestamp={threadTimeTimestamp(thread)} />
2567 </span>
2568 </span>
2569 {props.searchMatch ? (
@@ -4675,10 +4694,9 @@ export default function Sidebar() {
4694 )}
4695 >
4696 {(() => {
4678 - const renderThreadRowInner = (
4697 + const renderThreadRow = (
4698 thread: EnvironmentThreadShell,
4699 section: SidebarSection,
4681 - sortable?: SortableThreadRowBag,
4700 ) => {
4701 const threadKey = scopedThreadKey(
4702 scopeThreadRef(thread.environmentId, thread.id),
@@ -4687,8 +4705,16 @@ export default function Sidebar() {
4705 section === "active" || section === "pinned" || section === "working";
4706 const rowVariant = isCard ? "card" : "slim";
4707 return (
4690 - <SidebarThreadRow
4691 - key={`${threadKey}:${rowVariant}`}
4708 + <SortableThreadRow
4709 + key={threadKey}
4710 + sortableId={threadKey}
4711 + contextDrag={isContextDrag}
4712 + sortableDisabled={
4713 + renamingThreadKey === threadKey ||
4714 + section === "working" ||
4715 + !draggableThreadKeys.has(threadKey) ||
4716 + optimisticDrop !== null
4717 + }
4718 thread={thread}
4719 variant={rowVariant}
4720 variantAction={
@@ -4711,7 +4737,6 @@ export default function Sidebar() {
4737 .threadPinning === true
4738 }
4739 isPinned={thread.pinnedAt != null}
4714 - sortable={sortable}
4740 dropVerb={
4741 dragState?.activeKey === threadKey
4742 ? resolveSidebarDropVerb(dragState.activeSection, dragTargetSection)
@@ -4778,30 +4803,6 @@ export default function Sidebar() {
4803 />
4804 );
4805 };
4781 - const renderThreadRow = (
4782 - thread: EnvironmentThreadShell,
4783 - section: SidebarSection,
4784 - ) => {
4785 - const threadKey = scopedThreadKey(
4786 - scopeThreadRef(thread.environmentId, thread.id),
4787 - );
4788 - return (
4789 - <SortableThreadRow
4790 - key={threadKey}
4791 - id={threadKey}
4792 - contextDrag={isContextDrag}
4793 - environmentId={thread.environmentId}
4794 - disabled={
4795 - renamingThreadKey === threadKey ||
4796 - section === "working" ||
4797 - !draggableThreadKeys.has(threadKey) ||
4798 - optimisticDrop !== null
4799 - }
4800 - >
4801 - {(bag) => renderThreadRowInner(thread, section, bag)}
4802 - </SortableThreadRow>
4803 - );
4804 - };
4806 const from = isContextDrag ? null : (dragState?.activeSection ?? null);
4807 const items: ReactNode[] = [
4808 <SidebarDraftBlock
apps/web/src/timestampFormat.ts
+7 -4
@@ -249,13 +249,16 @@ export function formatRelativeElapsed(elapsedMs: number): RelativeTimeParts {
249 return { value: `${days}d`, suffix: "ago" };
250 }
251
252 -export function formatRelativeTime(isoDate: string): RelativeTimeParts | null {
253 - const elapsedMs = relativeTimeElapsedMs(isoDate);
252 +export function formatRelativeTime(
253 + isoDate: string,
254 + nowMs: number = Date.now(),
255 +): RelativeTimeParts | null {
256 + const elapsedMs = relativeTimeElapsedMs(isoDate, nowMs);
257 return elapsedMs === null ? null : formatRelativeElapsed(elapsedMs);
258 }
259
257 -export function formatRelativeTimeLabel(isoDate: string) {
258 - const relative = formatRelativeTime(isoDate);
260 +export function formatRelativeTimeLabel(isoDate: string, nowMs: number = Date.now()) {
261 + const relative = formatRelativeTime(isoDate, nowMs);
262 if (!relative) return "";
263 return relative.suffix ? `${relative.value} ${relative.suffix}` : relative.value;
264 }