Skip to content

Commit 06c8449

Browse files
committed
Merge remote-tracking branch 'upstream/main' into resolve-16045
2 parents 461ef0b + 07cb902 commit 06c8449

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
@@ -4752,25 +4752,35 @@ export default function ChatView(props: ChatViewProps) {
47524752
const supportsSnooze = serverConfig?.environment.capabilities.threadSnooze === true;
47534753
const supportsPinning = serverConfig?.environment.capabilities.threadPinning === true;
47544754
const activeThreadPinned = supportsPinning && activeThreadShell?.pinnedAt != null;
4755+
// The compiler caches render results on their inputs, so a clock read in render
4756+
// stays frozen until the shell changes. The clock is state: reset with the shell,
4757+
// and moved by the wake timer.
4758+
const [snoozeClockState, setSnoozeClockState] = useState(() => ({
4759+
shell: activeThreadShell,
4760+
now: new Date().toISOString(),
4761+
}));
4762+
if (snoozeClockState.shell !== activeThreadShell) {
4763+
setSnoozeClockState({ shell: activeThreadShell, now: new Date().toISOString() });
4764+
}
4765+
const snoozeClock = snoozeClockState.now;
47554766
const activeThreadSnoozed =
47564767
activeThreadShell !== null &&
47574768
supportsSnooze &&
4758-
effectiveSnoozed(activeThreadShell, { now: new Date().toISOString() });
4759-
const [snoozeWakeTick, bumpSnoozeWakeTick] = useState(0);
4769+
effectiveSnoozed(activeThreadShell, { now: snoozeClock });
47604770
useEffect(() => {
47614771
if (!activeThreadSnoozed) return;
47624772
const wakeAtMs = Date.parse(activeThreadShell?.snoozedUntil ?? "");
47634773
if (!Number.isFinite(wakeAtMs)) return;
47644774
const id = window.setTimeout(
4765-
() => bumpSnoozeWakeTick((tick) => tick + 1),
4775+
() => setSnoozeClockState((clock) => ({ ...clock, now: new Date().toISOString() })),
47664776
Math.min(Math.max(0, wakeAtMs - Date.now()) + 50, 2_147_483_647),
47674777
);
47684778
return () => window.clearTimeout(id);
4769-
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- A tick that lands before the wake time (timer clamping, clock skew) re-arms the timer.
4770-
}, [activeThreadShell?.snoozedUntil, activeThreadSnoozed, snoozeWakeTick]);
4779+
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- A clock that lands before the wake time (timer clamping, clock skew) re-arms the timer.
4780+
}, [activeThreadShell?.snoozedUntil, activeThreadSnoozed, snoozeClock]);
47714781
const activeThreadWokeAt =
47724782
activeThreadShell !== null && supportsSnooze
4773-
? threadWokeAt(activeThreadShell, { now: new Date().toISOString() })
4783+
? threadWokeAt(activeThreadShell, { now: snoozeClock })
47744784
: null;
47754785
const acknowledgeThreadWoke = useAcknowledgeThreadWoke();
47764786
const acknowledgeActiveThreadWoke = () => {

0 commit comments

Comments
 (0)