Skip to content
Source
Sign inSign up
pingdotgg/t3code

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

Mergedjuliusmarmingemerged 1 commit intomain fromrefs/pull/20814/headmerged by juliusmarminge View on GitHub

Showing 2 changed files with 64 additions and 60 deletions.

x
0 of 2 viewed, 2 left
57 additions and 56 deletionsapps/web/src/components/Sidebar.tsxModified
View file
@@ -758,14 +758,19 @@
return label.endsWith(" ago") ? label.slice(0, -4) : label;
​
-function threadTimeLabel(thread: SidebarThreadSummary): string {
- const timestamp = thread.latestUserMessageAt ?? thread.updatedAt;
- return compactSidebarTimeLabel(formatRelativeTimeLabel(timestamp));
+// Subscribes to the minute tick itself, so only the label re-renders each
+// minute. The minute is passed as the clock so it is the formatter's input.
+function RelativeTimeLabel(props: { timestamp: string | null }) {
+ const nowMinute = useNowMinute();
+ return props.timestamp === null
+ ? null
+ : compactSidebarTimeLabel(
+ formatRelativeTimeLabel(props.timestamp, Date.parse(`${nowMinute}:00.000Z`)),
+ );
​
-function settledTimeLabel(thread: SidebarThreadSummary): string {
- const timestamp = resolveSettledThreadTimestamp(thread);
- return timestamp === null ? "" : compactSidebarTimeLabel(formatRelativeTimeLabel(timestamp));
+function threadTimeTimestamp(thread: SidebarThreadSummary): string {
+ return thread.latestUserMessageAt ?? thread.updatedAt;
​
function JumpHintBadge(props: { label: string }) {
@@ -1052,18 +1057,25 @@
const SIDEBAR_SORTABLE_DRAG_DISABLED = { draggable: true } as const;
const SIDEBAR_SORTABLE_DRAG_ENABLED = { draggable: false } as const;