@@ -7014,25 +7014,35 @@ export default function ChatView(props: ChatViewProps) { |
7014 | 7014 | const supportsSnooze = serverConfig?.environment.capabilities.threadSnooze === true; |
7015 | 7015 | const supportsPinning = serverConfig?.environment.capabilities.threadPinning === true; |
7016 | 7016 | const activeThreadPinned = supportsPinning && activeThreadShell?.pinnedAt != null; |
| 7017 | + // The compiler caches render results on their inputs, so a clock read in render |
| 7018 | + // stays frozen until the shell changes. The clock is state: reset with the shell, |
| 7019 | + // and moved by the wake timer. |
| 7020 | + const [snoozeClockState, setSnoozeClockState] = useState(() => ({ |
| 7021 | + shell: activeThreadShell, |
| 7022 | + now: new Date().toISOString(), |
| 7023 | + })); |
| 7024 | + if (snoozeClockState.shell !== activeThreadShell) { |
| 7025 | + setSnoozeClockState({ shell: activeThreadShell, now: new Date().toISOString() }); |
| 7026 | + } |
| 7027 | + const snoozeClock = snoozeClockState.now; |
7017 | 7028 | const activeThreadSnoozed = |
7018 | 7029 | activeThreadShell !== null && |
7019 | 7030 | supportsSnooze && |
7020 | | - effectiveSnoozed(activeThreadShell, { now: new Date().toISOString() }); |
7021 | | - const [snoozeWakeTick, bumpSnoozeWakeTick] = useState(0); |
| 7031 | + effectiveSnoozed(activeThreadShell, { now: snoozeClock }); |
7022 | 7032 | useEffect(() => { |
7023 | | - void snoozeWakeTick; |
| 7033 | + void snoozeClock; |
7024 | 7034 | if (!activeThreadSnoozed) return; |
7025 | 7035 | const wakeAtMs = Date.parse(activeThreadShell?.snoozedUntil ?? ""); |
7026 | 7036 | if (!Number.isFinite(wakeAtMs)) return; |
7027 | 7037 | const id = window.setTimeout( |
7028 | | - () => bumpSnoozeWakeTick((tick) => tick + 1), |
| 7038 | + () => setSnoozeClockState((clock) => ({ ...clock, now: new Date().toISOString() })), |
7029 | 7039 | Math.min(Math.max(0, wakeAtMs - Date.now()) + 50, 2_147_483_647), |
7030 | 7040 | ); |
7031 | 7041 | return () => window.clearTimeout(id); |
7032 | | - }, [activeThreadShell?.snoozedUntil, activeThreadSnoozed, snoozeWakeTick]); |
| 7042 | + }, [activeThreadShell?.snoozedUntil, activeThreadSnoozed, snoozeClock]); |
7033 | 7043 | const activeThreadWokeAt = |
7034 | 7044 | activeThreadShell !== null && supportsSnooze |
7035 | | - ? threadWokeAt(activeThreadShell, { now: new Date().toISOString() }) |
| 7045 | + ? threadWokeAt(activeThreadShell, { now: snoozeClock }) |
7036 | 7046 | : null; |
7037 | 7047 | const acknowledgeThreadWoke = useAcknowledgeThreadWoke(); |
7038 | 7048 | const acknowledgeActiveThreadWoke = () => { |
|