Skip to content

Commit 07cb902

Browse files
fix(web): a snoozed thread wakes in the open chat view (pingdotgg#21019)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 13aa882 commit 07cb902

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

‎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 = () => {

0 commit comments

Comments
 (0)