Skip to content

Commit 643bc5d

Browse files
chore(web): merge main into snooze favorites
Keep the queued-turn snooze timer helpers from main and the snooze-favorite helpers in the shared Sidebar import.
2 parents edd0b4c + 96ff44e commit 643bc5d

21 files changed

Lines changed: 165 additions & 83 deletions

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4751,25 +4751,35 @@ export default function ChatView(props: ChatViewProps) {
47514751
const supportsSnooze = serverConfig?.environment.capabilities.threadSnooze === true;
47524752
const supportsPinning = serverConfig?.environment.capabilities.threadPinning === true;
47534753
const activeThreadPinned = supportsPinning && activeThreadShell?.pinnedAt != null;
4754+
// The compiler caches render results on their inputs, so a clock read in render
4755+
// stays frozen until the shell changes. The clock is state: reset with the shell,
4756+
// and moved by the wake timer.
4757+
const [snoozeClockState, setSnoozeClockState] = useState(() => ({
4758+
shell: activeThreadShell,
4759+
now: new Date().toISOString(),
4760+
}));
4761+
if (snoozeClockState.shell !== activeThreadShell) {
4762+
setSnoozeClockState({ shell: activeThreadShell, now: new Date().toISOString() });
4763+
}
4764+
const snoozeClock = snoozeClockState.now;
47544765
const activeThreadSnoozed =
47554766
activeThreadShell !== null &&
47564767
supportsSnooze &&
4757-
effectiveSnoozed(activeThreadShell, { now: new Date().toISOString() });
4758-
const [snoozeWakeTick, bumpSnoozeWakeTick] = useState(0);
4768+
effectiveSnoozed(activeThreadShell, { now: snoozeClock });
47594769
useEffect(() => {
47604770
if (!activeThreadSnoozed) return;
47614771
const wakeAtMs = Date.parse(activeThreadShell?.snoozedUntil ?? "");
47624772
if (!Number.isFinite(wakeAtMs)) return;
47634773
const id = window.setTimeout(
4764-
() => bumpSnoozeWakeTick((tick) => tick + 1),
4774+
() => setSnoozeClockState((clock) => ({ ...clock, now: new Date().toISOString() })),
47654775
Math.min(Math.max(0, wakeAtMs - Date.now()) + 50, 2_147_483_647),
47664776
);
47674777
return () => window.clearTimeout(id);
4768-
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- A tick that lands before the wake time (timer clamping, clock skew) re-arms the timer.
4769-
}, [activeThreadShell?.snoozedUntil, activeThreadSnoozed, snoozeWakeTick]);
4778+
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- A clock that lands before the wake time (timer clamping, clock skew) re-arms the timer.
4779+
}, [activeThreadShell?.snoozedUntil, activeThreadSnoozed, snoozeClock]);
47704780
const activeThreadWokeAt =
47714781
activeThreadShell !== null && supportsSnooze
4772-
? threadWokeAt(activeThreadShell, { now: new Date().toISOString() })
4782+
? threadWokeAt(activeThreadShell, { now: snoozeClock })
47734783
: null;
47744784
const acknowledgeThreadWoke = useAcknowledgeThreadWoke();
47754785
const acknowledgeActiveThreadWoke = () => {

‎apps/web/src/components/LegacySidebar.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ import { threadEnvironment, useEnvironmentThread } from "../state/threads";
131131
import { useEnvironment, useEnvironments, usePrimaryEnvironmentId } from "../state/environments";
132132
import { buildThreadRouteParams, resolveActiveThreadRouteRef } from "../threadRoutes";
133133
import { stackedThreadToast, toastManager } from "./ui/toast";
134-
import { formatRelativeTimeLabel } from "../timestampFormat";
134+
import { RelativeTime } from "./RelativeTime";
135135
import { Kbd } from "./ui/kbd";
136136
import {
137137
getArm64IntelBuildWarningDescription,
@@ -874,9 +874,9 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
874874
isHighlighted ? "text-foreground" : "text-secondary-label"
875875
}`}
876876
>
877-
{formatRelativeTimeLabel(
878-
thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt,
879-
)}
877+
<RelativeTime
878+
timestamp={thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt}
879+
/>
880880
</span>
881881
)}
882882
</span>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { useRelativeTimeState } from "../hooks/useRelativeTimeState";
2+
3+
// A "5m ago" label that keeps counting. Formatting the label inline in render
4+
// does not: the React Compiler caches it on the timestamp alone.
5+
export function RelativeTime(props: { timestamp: string }) {
6+
const relative = useRelativeTimeState(props.timestamp);
7+
if (relative.status !== "relative") return null;
8+
return relative.suffix ? `${relative.value} ${relative.suffix}` : relative.value;
9+
}

‎apps/web/src/components/RightPanelTabs.keyboard.browser.test.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,11 @@ describe("right panel new-tab shortcut", () => {
181181
expect(document.querySelector('[role="menu"]')).not.toBeNull();
182182
await press("Escape");
183183
expect(document.querySelector('[role="menu"]:not([data-closed])')).toBeNull();
184-
expect(document.activeElement).toBe(
185-
container.querySelector('[aria-label="Add panel surface"]'),
184+
// The menu hands focus back to its trigger once its close finishes, which can land a frame later.
185+
await vi.waitFor(() =>
186+
expect(document.activeElement).toBe(
187+
container.querySelector('[aria-label="Add panel surface"]'),
188+
),
186189
);
187190
input.remove();
188191
});

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import { CSS } from "@dnd-kit/utilities";
3333
import {
3434
canSnooze,
3535
effectiveSnoozed,
36+
hasQueuedTurnStart,
37+
QUEUED_TURN_START_GRACE_MS,
3638
removeSnoozeFavorite,
3739
snoozeFavoriteLabel,
3840
threadWokeAt,
@@ -1892,10 +1894,34 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
18921894
onSnooze(threadRef, preset);
18931895
};
18941896
const [snoozeMenuOpenRaw, setSnoozeMenuOpen] = useState(false);
1897+
// The React Compiler caches render results on their inputs, so a clock read
1898+
// here would stay frozen until `thread` changes and a queued-turn gate would
1899+
// never reopen. The gate's clock is state, reset with the thread.
1900+
const [snoozeGateClock, setSnoozeGateClock] = useState(() => ({
1901+
thread,
1902+
now: new Date().toISOString(),
1903+
}));
1904+
if (snoozeGateClock.thread !== thread) {
1905+
setSnoozeGateClock({ thread, now: new Date().toISOString() });
1906+
}
1907+
const snoozeGateNow = snoozeGateClock.now;
1908+
const snoozeGateExpiryMs = hasQueuedTurnStart(thread, { now: snoozeGateNow })
1909+
? Date.parse(thread.latestUserMessageAt ?? "") + QUEUED_TURN_START_GRACE_MS
1910+
: Number.NaN;
1911+
useEffect(() => {
1912+
// A gate still closed past its expiry is held by runtime status, not time,
1913+
// so no clock tick can open it.
1914+
if (!Number.isFinite(snoozeGateExpiryMs) || snoozeGateExpiryMs <= Date.parse(snoozeGateNow)) {
1915+
return;
1916+
}
1917+
const id = window.setTimeout(
1918+
() => setSnoozeGateClock({ thread, now: new Date().toISOString() }),
1919+
Math.min(Math.max(0, snoozeGateExpiryMs - Date.now()) + 50, 2_147_483_647),
1920+
);
1921+
return () => window.clearTimeout(id);
1922+
}, [snoozeGateExpiryMs, snoozeGateNow, thread]);
18951923
const showSnoozeButton =
1896-
canOperateThread &&
1897-
props.snoozeSupported &&
1898-
canSnooze(thread, { now: new Date().toISOString() });
1924+
canOperateThread && props.snoozeSupported && canSnooze(thread, { now: snoozeGateNow });
18991925
// Closing here, not just masking, keeps the menu from reopening when the button returns.
19001926
if (snoozeMenuOpenRaw && !showSnoozeButton) setSnoozeMenuOpen(false);
19011927
const snoozeMenuOpen = snoozeMenuOpenRaw && showSnoozeButton;

‎apps/web/src/components/chat/ComposerStashMenu.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BookmarkIcon, FileIcon, FileTextIcon } from "lucide-react";
22
import { memo, useEffect, useRef, useState } from "react";
33
import { assistantCitationsToPlainText } from "@t3tools/shared/assistantCitations";
44

5-
import { formatRelativeTimeLabel } from "../../timestampFormat";
5+
import { RelativeTime } from "../RelativeTime";
66
import { cn } from "~/lib/utils";
77
import { type PromptStashEntry } from "../../promptStashStore";
88
import { ComposerBanner } from "./ComposerBanner";
@@ -205,7 +205,7 @@ export const ComposerStashMenu = memo(function ComposerStashMenu(props: {
205205
dateTime={entry.createdAt}
206206
className="shrink-0 text-muted-foreground tabular-nums max-sm:hidden"
207207
>
208-
{formatRelativeTimeLabel(entry.createdAt)}
208+
<RelativeTime timestamp={entry.createdAt} />
209209
</time>
210210
<ComposerBanner.Dismiss
211211
className="z-10"

‎apps/web/src/components/chat/ThreadAutomationsPanel.tsx‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616

1717
import { ThreadDetailsSection } from "./ThreadDetailsSection";
1818
import { cn } from "../../lib/utils";
19-
import { relativeLabel, scheduleLabel } from "../settings/ScheduledTasksSettings";
19+
import { ScheduledRelativeLabel, scheduleLabel } from "../settings/ScheduledTasksSettings";
2020
import { useEnvironmentQuery } from "../../state/query";
2121
import { serverEnvironment } from "../../state/server";
2222
import { useAtomCommand } from "../../state/use-atom-command";
@@ -168,11 +168,16 @@ export function ThreadAutomationsPanel(props: {
168168
</span>
169169
<p className="truncate text-2xs text-muted-foreground">
170170
{scheduleLabel(task.schedule)}
171-
{task.enabled && task.nextRunAt !== null
172-
? ` · next ${relativeLabel(task.nextRunAt)}`
173-
: task.enabled
174-
? ""
175-
: " · paused"}
171+
{task.enabled && task.nextRunAt !== null ? (
172+
<>
173+
{" · next "}
174+
<ScheduledRelativeLabel value={task.nextRunAt} />
175+
</>
176+
) : task.enabled ? (
177+
""
178+
) : (
179+
" · paused"
180+
)}
176181
</p>
177182
</div>
178183
<Tooltip>

‎apps/web/src/components/preview/PreviewRecentUrlCard.tsx‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import type { ScopedThreadRef } from "@t3tools/contracts";
22
import { X } from "lucide-react";
33

44
import { isValidHistoryTimestamp, type BrowserHistoryEntry } from "~/browserHistoryStore";
5-
import { useNowMinute } from "~/hooks/useNowMinute";
6-
import { formatRelativeTimeLabel } from "~/timestampFormat";
5+
import { RelativeTime } from "~/components/RelativeTime";
76

87
import { PreviewFaviconIcon } from "./PreviewFaviconIcon";
98

@@ -18,10 +17,9 @@ export function PreviewRecentUrlCard({ threadRef, entry, onOpen, onRemove }: Pro
1817
const parsed = new URL(entry.url);
1918
const path = parsed.pathname === "/" ? "" : parsed.pathname;
2019
const label = `${parsed.host}${path}${parsed.search}${parsed.hash}`;
21-
const visitedAt = isValidHistoryTimestamp(entry.lastVisitedAt)
22-
? formatRelativeTimeLabel(new Date(entry.lastVisitedAt).toISOString())
23-
: "";
24-
useNowMinute();
20+
const visitedAt = isValidHistoryTimestamp(entry.lastVisitedAt) ? (
21+
<RelativeTime timestamp={new Date(entry.lastVisitedAt).toISOString()} />
22+
) : null;
2523
return (
2624
<div className="group relative flex w-full items-center">
2725
<button

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ import { PullRequestStackMenu } from "./PullRequestStackMenu";
9696
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
9797
import { PullRequestThreadLinks } from "./PullRequestThreadLinks";
9898
import { vcsEnvironment } from "~/state/vcs";
99-
import { formatRelativeTimeLabel } from "~/timestampFormat";
99+
import { RelativeTime } from "~/components/RelativeTime";
100100
import { useUiStateStore } from "~/uiStateStore";
101101

102102
import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
@@ -2340,7 +2340,9 @@ export function PullRequestDetailPanel({
23402340
variant="avatar"
23412341
className="shrink-0"
23422342
/>
2343-
<span className="shrink-0">{formatRelativeTimeLabel(detail.updatedAt)}</span>
2343+
<span className="shrink-0">
2344+
<RelativeTime timestamp={detail.updatedAt} />
2345+
</span>
23442346
</span>
23452347
<span aria-hidden className="h-3 w-px shrink-0 bg-border/70" />
23462348
<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({
25112513
author={
25122514
<PullRequestActorLabel actor={detail.author} profileUrl={authorProfileUrl} />
25132515
}
2514-
updated={<span>updated {formatRelativeTimeLabel(detail.updatedAt)}</span>}
2516+
updated={
2517+
<span>
2518+
updated <RelativeTime timestamp={detail.updatedAt} />
2519+
</span>
2520+
}
25152521
checkout={
25162522
checkoutCommand ? (
25172523
<PullRequestCopyableCode

‎apps/web/src/components/pullRequest/PullRequestGhosts.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { ReactNode } from "react";
1313

1414
import { readLocalApi } from "~/localApi";
1515
import { cn } from "~/lib/utils";
16-
import { formatRelativeTimeLabel } from "~/timestampFormat";
16+
import { RelativeTime } from "~/components/RelativeTime";
1717

1818
import { Button, InlineButton } from "../ui/button";
1919
import { MiddleTruncate } from "../ui/middle-truncate";
@@ -203,7 +203,9 @@ export function PullRequestDetailGhost({
203203
}
204204
updated={
205205
seed ? (
206-
<span>updated {formatRelativeTimeLabel(seed.updatedAt)}</span>
206+
<span>
207+
updated <RelativeTime timestamp={seed.updatedAt} />
208+
</span>
207209
) : (
208210
<GhostBar className="h-3 w-16" />
209211
)

0 commit comments

Comments
 (0)