Skip to content
TypeScript

fix(web): time-based labels update under the React Compiler (#21026)

Julius Marmingee712d9781535
diff --git a/apps/web/src/components/LegacySidebar.tsx b/apps/web/src/components/LegacySidebar.tsx
index 7dbd6d44155..884977f6cb5 100644
--- a/apps/web/src/components/LegacySidebar.tsx
+++ b/apps/web/src/components/LegacySidebar.tsx
@@ -131,7 +131,7 @@ import { threadEnvironment, useEnvironmentThread } from "../state/threads";
import { useEnvironment, useEnvironments, usePrimaryEnvironmentId } from "../state/environments";
import { buildThreadRouteParams, resolveActiveThreadRouteRef } from "../threadRoutes";
import { stackedThreadToast, toastManager } from "./ui/toast";
-import { formatRelativeTimeLabel } from "../timestampFormat";
+import { RelativeTime } from "./RelativeTime";
import { Kbd } from "./ui/kbd";
import {
getArm64IntelBuildWarningDescription,
@@ -874,9 +874,9 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
isHighlighted ? "text-foreground" : "text-secondary-label"
}`}
>
- {formatRelativeTimeLabel(
- thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt,
- )}
+ <RelativeTime
+ timestamp={thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt}
+ />
</span>
)}
</span>
diff --git a/apps/web/src/components/RelativeTime.tsx b/apps/web/src/components/RelativeTime.tsx
new file mode 100644
index 00000000000..663556d94f5
--- /dev/null
+++ b/apps/web/src/components/RelativeTime.tsx
@@ -0,0 +1,9 @@
+import { useRelativeTimeState } from "../hooks/useRelativeTimeState";
+
+// A "5m ago" label that keeps counting. Formatting the label inline in render
+// does not: the React Compiler caches it on the timestamp alone.
+export function RelativeTime(props: { timestamp: string }) {
+ const relative = useRelativeTimeState(props.timestamp);
+ if (relative.status !== "relative") return null;
+ return relative.suffix ? `${relative.value} ${relative.suffix}` : relative.value;
+}
diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx
index a1a2f30bbf1..d097eba3ae5 100644
--- a/apps/web/src/components/Sidebar.tsx
+++ b/apps/web/src/components/Sidebar.tsx
@@ -33,6 +33,8 @@ import { CSS } from "@dnd-kit/utilities";
import {
canSnooze,
effectiveSnoozed,
+ hasQueuedTurnStart,
+ QUEUED_TURN_START_GRACE_MS,
threadWokeAt,
} from "@t3tools/client-runtime/state/thread-settled";
import { createInboxReturnTracker } from "@t3tools/client-runtime/state/thread-inbox";
@@ -1853,10 +1855,34 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
onSnooze(threadRef, preset);
};
const [snoozeMenuOpenRaw, setSnoozeMenuOpen] = useState(false);
+ // The React Compiler caches render results on their inputs, so a clock read
+ // here would stay frozen until `thread` changes and a queued-turn gate would
+ // never reopen. The gate's clock is state, reset with the thread.
+ const [snoozeGateClock, setSnoozeGateClock] = useState(() => ({
+ thread,
+ now: new Date().toISOString(),
+ }));
+ if (snoozeGateClock.thread !== thread) {
+ setSnoozeGateClock({ thread, now: new Date().toISOString() });
+ }
+ const snoozeGateNow = snoozeGateClock.now;
+ const snoozeGateExpiryMs = hasQueuedTurnStart(thread, { now: snoozeGateNow })
+ ? Date.parse(thread.latestUserMessageAt ?? "") + QUEUED_TURN_START_GRACE_MS
+ : Number.NaN;
+ useEffect(() => {
+ // A gate still closed past its expiry is held by runtime status, not time,
+ // so no clock tick can open it.
+ if (!Number.isFinite(snoozeGateExpiryMs) || snoozeGateExpiryMs <= Date.parse(snoozeGateNow)) {
+ return;
+ }
+ const id = window.setTimeout(
+ () => setSnoozeGateClock({ thread, now: new Date().toISOString() }),
+ Math.min(Math.max(0, snoozeGateExpiryMs - Date.now()) + 50, 2_147_483_647),
+ );
+ return () => window.clearTimeout(id);
+ }, [snoozeGateExpiryMs, snoozeGateNow, thread]);
const showSnoozeButton =
- canOperateThread &&
- props.snoozeSupported &&
- canSnooze(thread, { now: new Date().toISOString() });
+ canOperateThread && props.snoozeSupported && canSnooze(thread, { now: snoozeGateNow });
// Closing here, not just masking, keeps the menu from reopening when the button returns.
if (snoozeMenuOpenRaw && !showSnoozeButton) setSnoozeMenuOpen(false);
const snoozeMenuOpen = snoozeMenuOpenRaw && showSnoozeButton;
diff --git a/apps/web/src/components/chat/ComposerStashMenu.tsx b/apps/web/src/components/chat/ComposerStashMenu.tsx
index a9f225f267c..066aadd02e1 100644
--- a/apps/web/src/components/chat/ComposerStashMenu.tsx
+++ b/apps/web/src/components/chat/ComposerStashMenu.tsx
@@ -2,7 +2,7 @@ import { BookmarkIcon, FileIcon, FileTextIcon } from "lucide-react";
import { memo, useEffect, useRef, useState } from "react";
import { assistantCitationsToPlainText } from "@t3tools/shared/assistantCitations";
-import { formatRelativeTimeLabel } from "../../timestampFormat";
+import { RelativeTime } from "../RelativeTime";
import { cn } from "~/lib/utils";
import { type PromptStashEntry } from "../../promptStashStore";
import { ComposerBanner } from "./ComposerBanner";
@@ -205,7 +205,7 @@ export const ComposerStashMenu = memo(function ComposerStashMenu(props: {
dateTime={entry.createdAt}
className="shrink-0 text-muted-foreground tabular-nums max-sm:hidden"
>
- {formatRelativeTimeLabel(entry.createdAt)}
+ <RelativeTime timestamp={entry.createdAt} />
</time>
<ComposerBanner.Dismiss
className="z-10"
diff --git a/apps/web/src/components/chat/ThreadAutomationsPanel.tsx b/apps/web/src/components/chat/ThreadAutomationsPanel.tsx
index 192805d2d54..94f6ff5b663 100644
--- a/apps/web/src/components/chat/ThreadAutomationsPanel.tsx
+++ b/apps/web/src/components/chat/ThreadAutomationsPanel.tsx
@@ -16,7 +16,7 @@ import {
import { ThreadDetailsSection } from "./ThreadDetailsSection";
import { cn } from "../../lib/utils";
-import { relativeLabel, scheduleLabel } from "../settings/ScheduledTasksSettings";
+import { ScheduledRelativeLabel, scheduleLabel } from "../settings/ScheduledTasksSettings";
import { useEnvironmentQuery } from "../../state/query";
import { serverEnvironment } from "../../state/server";
import { useAtomCommand } from "../../state/use-atom-command";
@@ -168,11 +168,16 @@ export function ThreadAutomationsPanel(props: {
</span>
<p className="truncate text-2xs text-muted-foreground">
{scheduleLabel(task.schedule)}
- {task.enabled && task.nextRunAt !== null
- ? ` · next ${relativeLabel(task.nextRunAt)}`
- : task.enabled
- ? ""
- : " · paused"}
+ {task.enabled && task.nextRunAt !== null ? (
+ <>
+ {" · next "}
+ <ScheduledRelativeLabel value={task.nextRunAt} />
+ </>
+ ) : task.enabled ? (
+ ""
+ ) : (
+ " · paused"
+ )}
</p>
</div>
<Tooltip>
diff --git a/apps/web/src/components/preview/PreviewRecentUrlCard.tsx b/apps/web/src/components/preview/PreviewRecentUrlCard.tsx
index afba72c805b..b6fe2c2b3fa 100644
--- a/apps/web/src/components/preview/PreviewRecentUrlCard.tsx
+++ b/apps/web/src/components/preview/PreviewRecentUrlCard.tsx
@@ -2,8 +2,7 @@ import type { ScopedThreadRef } from "@t3tools/contracts";
import { X } from "lucide-react";
import { isValidHistoryTimestamp, type BrowserHistoryEntry } from "~/browserHistoryStore";
-import { useNowMinute } from "~/hooks/useNowMinute";
-import { formatRelativeTimeLabel } from "~/timestampFormat";
+import { RelativeTime } from "~/components/RelativeTime";
import { PreviewFaviconIcon } from "./PreviewFaviconIcon";
@@ -18,10 +17,9 @@ export function PreviewRecentUrlCard({ threadRef, entry, onOpen, onRemove }: Pro
const parsed = new URL(entry.url);
const path = parsed.pathname === "/" ? "" : parsed.pathname;
const label = `${parsed.host}${path}${parsed.search}${parsed.hash}`;
- const visitedAt = isValidHistoryTimestamp(entry.lastVisitedAt)
- ? formatRelativeTimeLabel(new Date(entry.lastVisitedAt).toISOString())
- : "";
- useNowMinute();
+ const visitedAt = isValidHistoryTimestamp(entry.lastVisitedAt) ? (
+ <RelativeTime timestamp={new Date(entry.lastVisitedAt).toISOString()} />
+ ) : null;
return (
<div className="group relative flex w-full items-center">
<button
diff --git a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
index 2317001614f..624fc420e2c 100644
--- a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
+++ b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
@@ -96,7 +96,7 @@ import { PullRequestStackMenu } from "./PullRequestStackMenu";
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
import { PullRequestThreadLinks } from "./PullRequestThreadLinks";
import { vcsEnvironment } from "~/state/vcs";
-import { formatRelativeTimeLabel } from "~/timestampFormat";
+import { RelativeTime } from "~/components/RelativeTime";
import { useUiStateStore } from "~/uiStateStore";
import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
@@ -2340,7 +2340,9 @@ export function PullRequestDetailPanel({
variant="avatar"
className="shrink-0"
/>
- <span className="shrink-0">{formatRelativeTimeLabel(detail.updatedAt)}</span>
+ <span className="shrink-0">
+ <RelativeTime timestamp={detail.updatedAt} />
+ </span>
</span>
<span aria-hidden className="h-3 w-px shrink-0 bg-border/70" />
<span className="flex min-w-0 flex-1 items-center gap-1.5 font-mono text-2xs text-muted-foreground/65">
@@ -2511,7 +2513,11 @@ export function PullRequestDetailPanel({
author={
<PullRequestActorLabel actor={detail.author} profileUrl={authorProfileUrl} />
}
- updated={<span>updated {formatRelativeTimeLabel(detail.updatedAt)}</span>}
+ updated={
+ <span>
+ updated <RelativeTime timestamp={detail.updatedAt} />
+ </span>
+ }
checkout={
checkoutCommand ? (
<PullRequestCopyableCode
diff --git a/apps/web/src/components/pullRequest/PullRequestGhosts.tsx b/apps/web/src/components/pullRequest/PullRequestGhosts.tsx
index 90edd51b8ae..3294182d27c 100644
--- a/apps/web/src/components/pullRequest/PullRequestGhosts.tsx
+++ b/apps/web/src/components/pullRequest/PullRequestGhosts.tsx
@@ -13,7 +13,7 @@ import type { ReactNode } from "react";
import { readLocalApi } from "~/localApi";
import { cn } from "~/lib/utils";
-import { formatRelativeTimeLabel } from "~/timestampFormat";
+import { RelativeTime } from "~/components/RelativeTime";
import { Button, InlineButton } from "../ui/button";
import { MiddleTruncate } from "../ui/middle-truncate";
@@ -203,7 +203,9 @@ export function PullRequestDetailGhost({
}
updated={
seed ? (
- <span>updated {formatRelativeTimeLabel(seed.updatedAt)}</span>
+ <span>
+ updated <RelativeTime timestamp={seed.updatedAt} />
+ </span>
) : (
<GhostBar className="h-3 w-16" />
)
diff --git a/apps/web/src/components/pullRequest/PullRequestLinkPreview.tsx b/apps/web/src/components/pullRequest/PullRequestLinkPreview.tsx
index 7a68648e857..063416c731c 100644
--- a/apps/web/src/components/pullRequest/PullRequestLinkPreview.tsx
+++ b/apps/web/src/components/pullRequest/PullRequestLinkPreview.tsx
@@ -11,7 +11,7 @@ import {
type ReactNode,
} from "react";
-import { formatRelativeTimeLabel } from "~/timestampFormat";
+import { RelativeTime } from "~/components/RelativeTime";
import { pullRequestEnvironment } from "~/state/pullRequests";
import { useAtomQueryRunner } from "~/state/use-atom-query-runner";
import { useEnvironmentQuery } from "~/state/query";
@@ -139,7 +139,7 @@ export function PullRequestLinkPreview({
<span className="min-w-0 truncate">{authorLabel}</span>
<span aria-hidden>·</span>
<span className="shrink-0">
- opened {formatRelativeTimeLabel(detail.createdAt)}
+ opened <RelativeTime timestamp={detail.createdAt} />
</span>
</div>
</div>
diff --git a/apps/web/src/components/pullRequest/PullRequestListRow.tsx b/apps/web/src/components/pullRequest/PullRequestListRow.tsx
index 85f534ceaca..5599b1e1fc1 100644
--- a/apps/web/src/components/pullRequest/PullRequestListRow.tsx
+++ b/apps/web/src/components/pullRequest/PullRequestListRow.tsx
@@ -6,7 +6,7 @@ import type {
import type { ReactNode } from "react";
import { cn } from "~/lib/utils";
-import { formatRelativeTimeLabel } from "~/timestampFormat";
+import { RelativeTime } from "~/components/RelativeTime";
import { MiddleTruncate } from "../ui/middle-truncate";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
@@ -96,7 +96,7 @@ export function PullRequestRowLines({
{meta}
{updatedAt ? (
<span className="ml-auto shrink-0 whitespace-nowrap tabular-nums">
- {formatRelativeTimeLabel(updatedAt)}
+ <RelativeTime timestamp={updatedAt} />
</span>
) : null}
</span>
diff --git a/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx b/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx
index 51485062cfd..b42cdfd54a5 100644
--- a/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx
+++ b/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx
@@ -12,7 +12,7 @@ import { Circle, CircleCheck } from "lucide";
import { useRef, useState } from "react";
import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
-import { formatRelativeTimeLabel } from "~/timestampFormat";
+import { RelativeTime } from "~/components/RelativeTime";
import { cn } from "~/lib/utils";
import { Button } from "../ui/button";
@@ -266,7 +266,9 @@ export function ReviewThreadCard({
<article key={comment.id} className="group min-w-0">
<div className="flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
<PullRequestActorLabel actor={comment.author} />
- <span>{formatRelativeTimeLabel(comment.createdAt)}</span>
+ <span>
+ <RelativeTime timestamp={comment.createdAt} />
+ </span>
<PullRequestReactionBar
className="ml-auto justify-end"
reactions={comment.reactions ?? []}
diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx
index 68701e9d3fc..5e7b0027912 100644
--- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx
+++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx
@@ -24,7 +24,7 @@ import { pullRequestEnvironment } from "~/state/pullRequests";
import { useLocalStorage } from "~/hooks/useLocalStorage";
import { cn } from "~/lib/utils";
import { useOpenLink } from "~/browser/useOpenLink";
-import { formatRelativeTimeLabel } from "~/timestampFormat";
+import { RelativeTime } from "~/components/RelativeTime";
import { Button } from "../ui/button";
import { PullRequestEditButton } from "./PullRequestEditButton";
@@ -104,7 +104,9 @@ function CommentIdentity({
)
}
>
- <time dateTime={comment.createdAt}>{formatRelativeTimeLabel(comment.createdAt)}</time>
+ <time dateTime={comment.createdAt}>
+ <RelativeTime timestamp={comment.createdAt} />
+ </time>
</TooltipTrigger>
<TooltipPopup>
{new Date(comment.createdAt).toLocaleString()}
diff --git a/apps/web/src/components/pullRequest/PullRequestTimelineTab.tsx b/apps/web/src/components/pullRequest/PullRequestTimelineTab.tsx
index 17f777e9e18..6b5b26a8311 100644
--- a/apps/web/src/components/pullRequest/PullRequestTimelineTab.tsx
+++ b/apps/web/src/components/pullRequest/PullRequestTimelineTab.tsx
@@ -19,7 +19,7 @@ import { useState, type ReactNode } from "react";
import { cn } from "~/lib/utils";
import { readLocalApi } from "~/localApi";
import { pullRequestEnvironment } from "~/state/pullRequests";
-import { formatRelativeTimeLabel } from "~/timestampFormat";
+import { RelativeTime } from "~/components/RelativeTime";
import { Button } from "../ui/button";
import { PullRequestEditButton } from "./PullRequestEditButton";
@@ -220,7 +220,9 @@ function ConversationCard({
{event.reviewState ? <ReviewStateBadge state={event.reviewState} /> : null}
</div>
<PullRequestMetaLine className="mt-1 flex-wrap text-2xs text-muted-foreground">
- <span>{formatRelativeTimeLabel(event.at)}</span>
+ <span>
+ <RelativeTime timestamp={event.at} />
+ </span>
{event.path ? (
<span className="inline-flex min-w-0 items-center gap-1">
<FileCode2Icon aria-hidden className="size-3 shrink-0" />
@@ -327,7 +329,7 @@ function ConversationGroup({
</span>
<span className="block truncate text-3xs text-muted-foreground">
{actors.length.toLocaleString()} {actors.length === 1 ? "author" : "authors"} ·{" "}
- {formatRelativeTimeLabel(first.at)}
+ <RelativeTime timestamp={first.at} />
</span>
</span>
<ChevronDownIcon
@@ -388,7 +390,9 @@ function CommitEvent({
</div>
<div className="mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-3xs text-muted-foreground">
<code className="font-mono">{event.id.slice(0, 7)}</code>
- <span>{formatRelativeTimeLabel(event.at)}</span>
+ <span>
+ <RelativeTime timestamp={event.at} />
+ </span>
</div>
</div>
{event.additions !== null && event.deletions !== null ? (
@@ -429,7 +433,7 @@ function LifecycleEvent({ event }: { event: PullRequestTimelineEvent }) {
<span className="font-semibold text-foreground">{presentation.label}</span>
</div>
<div className="mt-0.5 text-2xs text-muted-foreground">
- {formatRelativeTimeLabel(event.at)}
+ <RelativeTime timestamp={event.at} />
</div>
</div>
</div>
@@ -483,7 +487,9 @@ function ReviewVerdictEvent({
</div>
<div className="mt-0.5 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1">
<PullRequestMetaLine className="flex-wrap text-2xs text-muted-foreground">
- <span>{formatRelativeTimeLabel(event.at)}</span>
+ <span>
+ <RelativeTime timestamp={event.at} />
+ </span>
{event.path ? (
<span className="inline-flex min-w-0 items-center gap-1">
<FileCode2Icon aria-hidden className="size-3 shrink-0" />
diff --git a/apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx b/apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx
index 7cca27f92e3..4abafb7fc80 100644
--- a/apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx
+++ b/apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx
@@ -30,7 +30,7 @@ import { useProjects, useServerConfigs, useThreadShell } from "~/state/entities"
import { PullRequestsUnavailableState } from "./PullRequestsUnavailableState";
import { threadEnvironment } from "~/state/threads";
import { useAtomCommand } from "~/state/use-atom-command";
-import { formatRelativeTimeLabel } from "~/timestampFormat";
+import { RelativeTime } from "~/components/RelativeTime";
import { Button } from "../ui/button";
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
import { MiddleTruncate } from "../ui/middle-truncate";
@@ -181,7 +181,7 @@ function LinkRowImpl({
#{link.number}
</TooltipTrigger>
<TooltipPopup>
- {SOURCE_LABELS[link.source]} · {formatRelativeTimeLabel(link.linkedAt)}
+ {SOURCE_LABELS[link.source]} · <RelativeTime timestamp={link.linkedAt} />
</TooltipPopup>
</Tooltip>
}
@@ -376,7 +376,6 @@ function EnabledThreadPullRequestsPanel({ threadRef }: { threadRef: ScopedThread
(link) => link.snapshot === null || link.snapshot.state === "open",
).length;
const lastSynced = latestSyncedAt(links);
- const syncedLabel = lastSynced ? ` · synced ${formatRelativeTimeLabel(lastSynced)}` : "";
const linkCount = links.length;
const modifiers = useShortcutModifierState(true);
const speedMode =
@@ -462,7 +461,12 @@ function EnabledThreadPullRequestsPanel({ threadRef }: { threadRef: ScopedThread
<footer className="flex items-center justify-between border-t border-border/60 px-2 py-1.5 text-2xs text-muted-foreground">
<span>
{openCount} open · {linkCount} linked
- {syncedLabel}
+ {lastSynced ? (
+ <>
+ {" · synced "}
+ <RelativeTime timestamp={lastSynced} />
+ </>
+ ) : null}
</span>
<Button size="xs" variant="ghost" onClick={openLinkDialog}>
<PlusIcon className="size-3.5" />
diff --git a/apps/web/src/components/settings/DiagnosticsSettings.tsx b/apps/web/src/components/settings/DiagnosticsSettings.tsx
index fbac3df05fd..f30ca4603ad 100644
--- a/apps/web/src/components/settings/DiagnosticsSettings.tsx
+++ b/apps/web/src/components/settings/DiagnosticsSettings.tsx
@@ -23,7 +23,6 @@ import * as Option from "effect/Option";
import { cn } from "../../lib/utils";
import { ensureLocalApi } from "../../localApi";
import { useOpenInPreferredEditor } from "../../editorPreferences";
-import { formatRelativeTimeLabel } from "../../timestampFormat";
import { useRelativeTimeState } from "../../hooks/useRelativeTimeState";
import { useEnvironmentQuery } from "../../state/query";
import { serverEnvironment } from "../../state/server";
@@ -64,13 +63,10 @@ function formatBytes(value: number): string {
return `${next.toFixed(next >= 10 ? 1 : 2)} ${units[unitIndex]}`;
}
-function formatRelative(value: DateTime.Utc | null): string {
- if (!value) return "No trace records";
- return formatRelativeTimeLabel(DateTime.formatIso(value));
-}
-
-function formatRelativeNoWrap(value: DateTime.Utc | null): string {
- return formatRelative(value).replaceAll(" ", "\u00a0");
+function RelativeTimeNoWrap(props: { value: DateTime.Utc }) {
+ const relative = useRelativeTimeState(DateTime.formatIso(props.value));
+ if (relative.status !== "relative") return null;
+ return relative.suffix ? `${relative.value}\u00a0${relative.suffix}` : relative.value;
}
function shortenTraceId(traceId: string): string {
@@ -1182,7 +1178,7 @@ export function DiagnosticsSettingsPanel() {
{formatDuration(failure.durationMs)}
</td>
<td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums text-muted-foreground last:sm:pr-5">
- {formatRelativeNoWrap(failure.endedAt)}
+ <RelativeTimeNoWrap value={failure.endedAt} />
</td>
</tr>
))}
@@ -1210,7 +1206,7 @@ export function DiagnosticsSettingsPanel() {
<ExpandableText text={failure.cause} />
</td>
<td className="w-px whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums text-muted-foreground last:sm:pr-5">
- {formatRelativeNoWrap(failure.lastSeenAt)}
+ <RelativeTimeNoWrap value={failure.lastSeenAt} />
</td>
</tr>
))}
@@ -1238,7 +1234,7 @@ export function DiagnosticsSettingsPanel() {
{formatDuration(span.durationMs)}
</td>
<td className="w-px whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums text-muted-foreground">
- {formatRelativeNoWrap(span.endedAt)}
+ <RelativeTimeNoWrap value={span.endedAt} />
</td>
<td className="min-w-0 whitespace-nowrap px-4 py-3 align-top text-muted-foreground last:sm:pr-5">
<TraceIdCell traceId={span.traceId} />
@@ -1284,7 +1280,7 @@ export function DiagnosticsSettingsPanel() {
className="hover:bg-muted/15"
>
<td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums text-muted-foreground sm:pl-5">
- {formatRelativeNoWrap(event.seenAt)}
+ <RelativeTimeNoWrap value={event.seenAt} />
</td>
<td className="px-4 py-3 align-top">
<span className="inline-flex rounded bg-muted px-1.5 py-0.5 font-mono text-2xs font-medium uppercase text-foreground/80">
diff --git a/apps/web/src/components/settings/ScheduledTasksSettings.tsx b/apps/web/src/components/settings/ScheduledTasksSettings.tsx
index e85d17da5be..c22bdc188db 100644
--- a/apps/web/src/components/settings/ScheduledTasksSettings.tsx
+++ b/apps/web/src/components/settings/ScheduledTasksSettings.tsx
@@ -51,6 +51,7 @@ import { requestConfirmDialog } from "../../confirmDialog";
import { webhookAddress } from "@t3tools/client-runtime/webhook-address";
import { Link } from "@tanstack/react-router";
import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";
+import { useNowMinute } from "../../hooks/useNowMinute";
import {
useEnvironment,
useEnvironmentHttpBaseUrl,
@@ -108,7 +109,6 @@ import {
SettingsRow,
SettingsSection,
SETTINGS_PICKER_TRIGGER_CLASSNAME,
- useRelativeTimeTick,
} from "./settingsLayout";
const WEEKDAY_ORDER = [1, 2, 3, 4, 5, 6, 0] as const;
@@ -202,11 +202,11 @@ export function scheduleLabel(schedule: ScheduledTaskSchedule): string {
* instant — render "in 5m" style labels for upcoming runs instead of a
* misleading "just now".
*/
-export function relativeLabel(value: string | null): string {
+function relativeLabel(value: string | null, nowMs: number): string {
if (!value) return "Not scheduled";
- const diffMs = new Date(value).getTime() - Date.now();
+ const diffMs = new Date(value).getTime() - nowMs;
if (diffMs <= 0) {
- const relative = formatRelativeTime(value);
+ const relative = formatRelativeTime(value, nowMs);
if (!relative) return "Not scheduled";
return relative.suffix ? `${relative.value} ${relative.suffix}` : relative.value;
}
@@ -218,6 +218,13 @@ export function relativeLabel(value: string | null): string {
return `in ${Math.round(hours / 24)}d`;
}
+// The clock is the label's own minute tick: the React Compiler caches a
+// `Date.now()` read in render on the timestamp alone.
+export function ScheduledRelativeLabel(props: { value: string | null }) {
+ const nowMinute = useNowMinute();
+ return relativeLabel(props.value, Date.parse(`${nowMinute}:00.000Z`));
+}
+
const DELIVERY_OUTCOME_LABELS: Record<ScheduledTaskWebhookDeliveryOutcome, string> = {
accepted: "Ran",
dispatch_failed: "Run failed",
@@ -372,7 +379,6 @@ function ScheduledTaskEnvironmentList({
onEdit(environmentId, linkedTask);
}
}, [environmentId, linkedTask, onEdit]);
- useRelativeTimeTick(60_000);
const loaded = states.filter((state) => state.connected && state.error === null && state.tasks);
const populated = loaded.filter((state) => state.tasks && state.tasks.length > 0);
@@ -504,7 +510,6 @@ function ScheduledTaskEnvironmentSection({
onEdit(environment.environmentId, linkedTask);
}
}, [environment.environmentId, linkedTask, onEdit]);
- useRelativeTimeTick(60_000);
return (
<SettingsSection
title={environment.label}
@@ -607,13 +612,17 @@ function ScheduledTaskRow({
<div className="flex flex-wrap items-center gap-2">
<span>
{scheduleLabel(task.schedule)} ·{" "}
- {!task.enabled
- ? "Paused"
- : isWebhook
- ? "Listening"
- : task.nextRunAt
- ? `Next run ${relativeLabel(task.nextRunAt)}`
- : "Not scheduled"}
+ {!task.enabled ? (
+ "Paused"
+ ) : isWebhook ? (
+ "Listening"
+ ) : task.nextRunAt ? (
+ <>
+ Next run <ScheduledRelativeLabel value={task.nextRunAt} />
+ </>
+ ) : (
+ "Not scheduled"
+ )}
</span>
{task.lastRunStatus !== "never" ? (
<Badge variant={statusVariant(task.lastRunStatus)}>{task.lastRunStatus}</Badge>
@@ -730,7 +739,7 @@ function WebhookDeliveriesDialog({
{DELIVERY_OUTCOME_LABELS[selected.outcome]}
</Badge>
<span>
- {selected.method} · {relativeLabel(selected.receivedAt)}
+ {selected.method} · <ScheduledRelativeLabel value={selected.receivedAt} />
</span>
{selected.signatureVerified ? (
<span className="text-muted-foreground">Signature verified</span>
@@ -777,7 +786,7 @@ function WebhookDeliveriesDialog({
</Badge>
<span>{delivery.method}</span>
<span className="text-muted-foreground">
- {relativeLabel(delivery.receivedAt)}
+ <ScheduledRelativeLabel value={delivery.receivedAt} />
</span>
{delivery.missingFields.length > 0 ? (
<span className="text-muted-foreground">
diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsx
index 4ed6edccc08..64042f9200b 100644
--- a/apps/web/src/components/settings/SettingsPanels.tsx
+++ b/apps/web/src/components/settings/SettingsPanels.tsx
@@ -105,7 +105,7 @@ import { isMacPlatform } from "../../lib/utils";
import { useEnvironmentProviders } from "../../state/environments";
import { EMPTY_SERVER_PROVIDERS } from "../../state/server";
import { useArchivedThreadSnapshots } from "../../lib/archivedThreadsState";
-import { formatRelativeTimeLabel } from "../../timestampFormat";
+import { RelativeTime } from "../RelativeTime";
import { Button } from "../ui/button";
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
import {
@@ -3510,9 +3510,9 @@ export function ArchivedThreadsPanel() {
description={
<span className={hasMultipleEnvironments ? "block truncate" : undefined}>
{hasMultipleEnvironments ? `${thread.environmentLabel} · ` : null}
- Archived {formatRelativeTimeLabel(thread.archivedAt ?? thread.createdAt)}
+ Archived <RelativeTime timestamp={thread.archivedAt ?? thread.createdAt} />
{" \u00b7 Created "}
- {formatRelativeTimeLabel(thread.createdAt)}
+ <RelativeTime timestamp={thread.createdAt} />
</span>
}
control={
diff --git a/apps/web/src/timestampFormat.test.ts b/apps/web/src/timestampFormat.test.ts
index d033bc6d362..9d001ffc56e 100644
--- a/apps/web/src/timestampFormat.test.ts
+++ b/apps/web/src/timestampFormat.test.ts
@@ -287,6 +287,8 @@ describe("relative time boundaries", () => {
expect(msUntilRelativeTimeChange("2026-04-05T00:00:00.000Z", nowMs)).toBe(12 * 3_600_000);
// A future timestamp reads "just now" until a minute after it.
expect(msUntilRelativeTimeChange("2026-04-07T12:00:10.000Z", nowMs)).toBe(70_000);
+ // A far-future timestamp stays within setTimeout's range.
+ expect(msUntilRelativeTimeChange("2026-06-01T00:00:00.000Z", nowMs)).toBe(86_400_000);
});
it("keeps the elapsed snapshot stable while the label is unchanged", () => {
diff --git a/apps/web/src/timestampFormat.ts b/apps/web/src/timestampFormat.ts
index c1d1b2446c1..c6eae0ce6dd 100644
--- a/apps/web/src/timestampFormat.ts
+++ b/apps/web/src/timestampFormat.ts
@@ -235,7 +235,9 @@ export function msUntilRelativeTimeChange(
const elapsedMs = Math.max(0, nowMs - date.getTime());
const unitMs = relativeTimeUnitMs(elapsedMs);
const nextChangeMs = date.getTime() + (Math.floor(elapsedMs / unitMs) + 1) * unitMs;
- return nextChangeMs - nowMs;
+ // setTimeout fires at once past 2^31-1 ms, which would loop on a far-future
+ // timestamp. Waking early is harmless: the caller re-reads and re-schedules.
+ return Math.min(nextChangeMs - nowMs, DAY_MS);
}
export function formatRelativeElapsed(elapsedMs: number): RelativeTimeParts {