Repository navigation
fix: refresh the shared clock when the first component subscribes again - #517
Merged
brendt merged 1 commit intoOct 20, 2026
Merged
Conversation
jubianchi
marked this pull request as ready for review
October 18, 2026 21:27
jubianchi
force-pushed
the
fix/use-now-refresh-on-resubscribe
branch
from
October 19, 2026 19:42
b593949 to
37e4229
Compare
The `useNow` store keeps a module-level `now` and runs its 30 s interval only while at least one component is subscribed. When the last subscriber unmounts, the interval stops, and the next subscription restarted it without reading the clock: `now` kept the value of the moment the interval stopped until the first tick. Inertia keeps module state across navigations, so after a few minutes on a page without timestamps (Appearance, Terminal, Safety, About, Terms, Privacy) and back to the log, every relative age was behind by the time spent away for up to 30 s: commits posted meanwhile showed "now", older ones were rejuvenated, poll countdowns were stretched, and then everything jumped at once on the first tick. Read the clock again when the interval is restarted, so the first render after coming back is right away. The test drives the hook through a mocked `useSyncExternalStore` with fake timers: subscribe, unsubscribe, move the system clock ten minutes, subscribe again and expect the new time, then tick once to cover the interval. 🤖 Generated with Claude Code
jubianchi
force-pushed
the
fix/use-now-refresh-on-resubscribe
branch
from
October 20, 2026 09:02
37e4229 to
59fe98d
Compare
jubianchi
marked this pull request as draft
October 20, 2026 09:02
jubianchi
marked this pull request as ready for review
October 20, 2026 09:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
useNowkeeps a module-levelnowand runs its 30 s interval only while a component is subscribed. When the last subscriber unmounts, the interval stops; the next subscription restarted it without reading the clock, sonowkept its old value until the first tick.Inertia keeps module state across navigations. Spend a few minutes on a page without timestamps (Appearance, Terminal, Safety, About, Terms, Privacy), come back to the log, and for up to 30 s every relative age is behind by the time spent away: a commit posted meanwhile shows "now", older ones look younger, poll countdowns are stretched, then everything jumps at once.
Local check, back from Terminal after ~2 min, Remotes chat undocked (the dock keeps a subscriber alive):
Changes
subscribereadsDate.now()when it restarts the interval. One line.tests/Unit/UseNow.test.tsx: mockeduseSyncExternalStoreand fake timers; subscribe, unsubscribe, move the clock ten minutes, subscribe again, tick once. Red before, green after.tests/draft-images.config.tsandtests/tsconfig.json; trivial conflict with test: run the ten component tests that CI never ran #492, which replaces those lists by globs.Out of scope, noted for later: with SSR enabled (
config/inertia.php), the same module value is the render server's start time until hydration replaces it.