Skip to content

Commit 54b1618

Browse files
t3dotggclaude
andcommitted
fix(web): re-read useNowMinute snapshot when no timer is live
After the last consumer unmounted, the module-level minute froze and a remount's first render served the stale value (subscribe refreshed it without notifying React). getSnapshot now re-reads the clock whenever no timer is running, so a fresh mount renders the current minute; while subscribed, the cached snapshot stays stable as React requires. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent bd0b8cb commit 54b1618

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎apps/web/src/hooks/useNowMinute.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ function startTimer(): void {
3939

4040
function subscribe(listener: () => void): () => void {
4141
if (listeners.size === 0) {
42-
// The stored minute may have gone stale while no one was subscribed.
43-
nowMinute = currentMinute();
4442
startTimer();
4543
}
4644
listeners.add(listener);
@@ -55,6 +53,14 @@ function subscribe(listener: () => void): () => void {
5553
}
5654

5755
function getSnapshot(): string {
56+
// With no timer running (no subscribers yet — e.g. the first render after
57+
// a full unmount), the stored minute may be stale; re-read it so a fresh
58+
// mount renders the current minute instead of waiting for the first tick.
59+
// While the timer runs the cached value is returned untouched, as
60+
// useSyncExternalStore requires between change notifications.
61+
if (timerId === null) {
62+
nowMinute = currentMinute();
63+
}
5864
return nowMinute;
5965
}
6066

0 commit comments

Comments
 (0)