Repository navigation
feat(streak): toast the day's streak on the first counted read - #7374
Conversation
The milestone modal is the only streak celebration today, and it only
fires on Fibonacci days. The daily moment, the read that actually
extended the streak, had no feedback beyond the rail tile's 700 ms ring
pop, which is off-screen on the post page.
Behind the streak_daily_celebration flag (default off), useViewPost now
shows a "Day {n}! See you tomorrow." toast with the streak flame after
the first counted read of a local day. It reuses the first-view decision
already made in onMutate, waits for the streak refetch and takes n from
the server value, falling back to the count the optimistic update aimed
for when the refetch failed. The flame pops in with a keyframe gated on
motion-safe.
The toast stays away on days the milestone modal takes over: when
alerts.showStreakMilestone is already set, or when the refetched count is
a milestone by the API's own rule (Fibonacci and above 1, mirrored in
lib/streakDailyCelebration.ts), since the alert only reaches the client
on the next boot. It is also skipped when streaks are opted out and in
the extension companion, which has no streak in its cache and would
treat every read as the first of the day.
A per-user localStorage marker (dailydev:streak:celebrated:<userId>)
holding the local date in the profile timezone keeps it to one toast a
day, so an optimistic replay or a second tab does not toast twice. The
toast logs an impression with target type `streak daily celebration` and
the count as target_id.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
rebelchris
left a comment
There was a problem hiding this comment.
One blocker, inherited from the refetch race in #7373 but visible to users here, and one experiment note. The re-run is green.
Reviewed by AI.
|
|
||
| const refetched = client.getQueryState<UserStreak>(streakKey); | ||
| celebrateStreakDay( | ||
| refetched?.status === 'success' |
There was a problem hiding this comment.
Blocking: status === 'success' does not mean the refetch saw this read. viewPost only publishes the view, and workers/newView.ts increments the streak asynchronously, so the refetch can return yesterday's current. In that case the toast says "Day N!" when the user is on N+1, and the milestone check is run against the wrong number. On a milestone day (say the user reaches 8), the stale 7 is not a Fibonacci number, so the toast fires, and on the next boot the milestone modal shows 8. That is two celebrations with two different numbers.
Only trust the refetched current if its lastViewAt is today in the user's timezone, and otherwise fall back to context.nextStreak. The same guard fixes the optimistic cache in #7373. Please add a spec where the refetch returns the pre-view streak.
Reviewed by AI.
There was a problem hiding this comment.
Fixed in f15ba4c, which merges the updated #7373. The refetch helper in onSuccess now resolves with the refetched streak only when hasStreakViewToday passes (the helper from #7373: lastViewAt is today in the profile timezone). The toast gets countedStreak?.current ?? context.nextStreak, so the number and the milestone check use the count this read lands on whenever the refetch is behind. When the optimistic flag is on, the toast also waits for the single retry. Specs: the refetch returns the pre-view 7 on a 7 → 8 day and no toast fires because 8 is a milestone, both with the optimistic flag off and with the flag on where the retry is stale too. Also, a stale refetch on 5 → 6 toasts "Day 6!".
| const { logEvent } = useLogContext(); | ||
| const { value: isEnabled } = useConditionalFeature({ | ||
| feature: featureStreakDailyCelebration, | ||
| shouldEvaluate: !!user && !isCompanion, |
There was a problem hiding this comment.
Non-blocking (experiment hygiene): users who opted out of reading streaks are enrolled every time they open a post, but isStreaksEnabled means they can never see the toast, so they dilute both arms. Add isStreaksEnabled to shouldEvaluate (!!user && !isCompanion && isStreaksEnabled). That keeps the user out of the experiment while settings are still loading as well.
Reviewed by AI.
There was a problem hiding this comment.
Fixed in f15ba4c: shouldEvaluate: !!user && !isCompanion && isStreaksEnabled, where isStreaksEnabled is loadedSettings && !optOutReadingStreak. Specs check that streak_daily_celebration is never evaluated for a user who opted out, or while settings are still loading.
…ebration fix(streak): only toast a refetched streak that counts this read - The toast (and its milestone check) uses the refetched current only when its lastViewAt is today in the profile timezone. Otherwise it falls back to the count this read lands on (context.nextStreak), so a refetch that races the newView worker on 7 -> 8 no longer toasts "Day 7!" on a milestone day. - streak_daily_celebration is only evaluated for users with streaks enabled and settings loaded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rebelchris
left a comment
There was a problem hiding this comment.
Re-checked at f25b26d. Fixed: the toast and the milestone check now use the refetched count only when it includes this read, and fall back to nextStreak otherwise. streak_daily_celebration is no longer evaluated for opted-out users or while settings are loading. No new findings. CI is green.
Process note: these fixes were made while resolving conflicts in merge commit f15ba4c, not in a commit of their own, so they do not appear in the commit list. Next time, a separate fix commit makes the change easier to follow.
Reviewed by AI.
…ebration # Conflicts: # packages/shared/src/hooks/post/useViewPost.ts
…uiet after a gap The daily toast fell back to current + 1 when the refetch had not caught up. After a gap the API may reset or freeze the streak, so there is no safe guess: only a refetch that includes the read is toasted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Changes
streak_daily_celebration: on the first counted read of a local day, a toast "Day {n}! See you tomorrow." with a flame pop (static with reduced motion).currentonly if itslastViewAtis today in the profile timezone (the same helper as feat(streak): count the read on open and retry dropped views #7373). Otherwise they use the count this read lands on. A refetch that races the API'snewViewworker therefore can't toast the previous day's number, or toast on a milestone day such as 7 → 8.Events
Experiment
Yes:
streak_daily_celebration(A/B, default off). Evaluated only for signed-in users who have streaks enabled and settings loaded, outside the companion. #experiments message not posted yet.Manual Testing
Spec:
useViewPost.spec.tsx(including a pre-view refetch on a 7 → 8 milestone day, and no flag evaluation for opted-out users).🤖 Generated with Claude Code
Preview domain
https://feat-streak-daily-celebration.preview.app.daily.dev