Skip to content
TypeScript

fix(web): a snoozed thread wakes in the open chat view (#21019)

Julius Marminge07cb90286656
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index 10baf8ec91b..f9c107a6e79 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -4751,25 +4751,35 @@ export default function ChatView(props: ChatViewProps) {
const supportsSnooze = serverConfig?.environment.capabilities.threadSnooze === true;
const supportsPinning = serverConfig?.environment.capabilities.threadPinning === true;
const activeThreadPinned = supportsPinning && activeThreadShell?.pinnedAt != null;
+ // The compiler caches render results on their inputs, so a clock read in render
+ // stays frozen until the shell changes. The clock is state: reset with the shell,
+ // and moved by the wake timer.
+ const [snoozeClockState, setSnoozeClockState] = useState(() => ({
+ shell: activeThreadShell,
+ now: new Date().toISOString(),
+ }));
+ if (snoozeClockState.shell !== activeThreadShell) {
+ setSnoozeClockState({ shell: activeThreadShell, now: new Date().toISOString() });
+ }
+ const snoozeClock = snoozeClockState.now;
const activeThreadSnoozed =
activeThreadShell !== null &&
supportsSnooze &&
- effectiveSnoozed(activeThreadShell, { now: new Date().toISOString() });
- const [snoozeWakeTick, bumpSnoozeWakeTick] = useState(0);
+ effectiveSnoozed(activeThreadShell, { now: snoozeClock });
useEffect(() => {
if (!activeThreadSnoozed) return;
const wakeAtMs = Date.parse(activeThreadShell?.snoozedUntil ?? "");
if (!Number.isFinite(wakeAtMs)) return;
const id = window.setTimeout(
- () => bumpSnoozeWakeTick((tick) => tick + 1),
+ () => setSnoozeClockState((clock) => ({ ...clock, now: new Date().toISOString() })),
Math.min(Math.max(0, wakeAtMs - Date.now()) + 50, 2_147_483_647),
);
return () => window.clearTimeout(id);
- // oxlint-disable-next-line react/exhaustive-effect-dependencies -- A tick that lands before the wake time (timer clamping, clock skew) re-arms the timer.
- }, [activeThreadShell?.snoozedUntil, activeThreadSnoozed, snoozeWakeTick]);
+ // oxlint-disable-next-line react/exhaustive-effect-dependencies -- A clock that lands before the wake time (timer clamping, clock skew) re-arms the timer.
+ }, [activeThreadShell?.snoozedUntil, activeThreadSnoozed, snoozeClock]);
const activeThreadWokeAt =
activeThreadShell !== null && supportsSnooze
- ? threadWokeAt(activeThreadShell, { now: new Date().toISOString() })
+ ? threadWokeAt(activeThreadShell, { now: snoozeClock })
: null;
const acknowledgeThreadWoke = useAcknowledgeThreadWoke();
const acknowledgeActiveThreadWoke = () => {