Skip to content

fix: prevent archived day from reappearing after hard refresh#139

Merged
AdamJ merged 1 commit into
mainfrom
fix/archive-stale-closure-refresh
May 25, 2026
Merged

fix: prevent archived day from reappearing after hard refresh#139
AdamJ merged 1 commit into
mainfrom
fix/archive-stale-closure-refresh

Conversation

@AdamJ
Copy link
Copy Markdown
Owner

@AdamJ AdamJ commented May 25, 2026

Summary

  • Root cause: beforeunload and handleBackground captured stale closure values via their useEffect/useCallback deps. If the user hard-refreshed immediately after archiving — before React re-rendered and re-registered the handler — the old handler fired with isDayStarted=true and the pre-archive task list, overwriting the correctly-cleared localStorage entry.
  • Fix 1: Both handlers now read latestStateRef.current instead of closed-over state vars, eliminating the stale-closure window entirely.
  • Fix 2: archiveDay updates latestStateRef.current synchronously (before any await) so the ref reflects the cleared state the instant the setters are called, not after the next React render.

Test plan

  • Start a day, add tasks, archive the day
  • Immediately hard-refresh (Cmd+Shift+R) — should show "Start Day" screen, not the archived tasks
  • Repeat with a normal refresh (Cmd+R) to confirm no regression
  • Verify the archived day still appears correctly in the archive/history view

🤖 Generated with Claude Code

beforeunload and handleBackground captured stale closure values. If user
did a hard refresh immediately after archiving (before React re-rendered
and re-registered the handler), the old handler would overwrite the
correctly-cleared localStorage with pre-archive task data.

Fix: read latestStateRef.current in both handlers so they always see the
current state regardless of React's render cycle. Also update the ref
synchronously in archiveDay before any awaits so it's correct the moment
state setters fire.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying timetrackerpro with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5ef9c8b
Status: ✅  Deploy successful!
Preview URL: https://3dc26d73.timetrackerpro.pages.dev
Branch Preview URL: https://fix-archive-stale-closure-re.timetrackerpro.pages.dev

View logs

@AdamJ AdamJ added fix For general fixes or bundled fixes performance For performance related issues labels May 25, 2026
@AdamJ AdamJ merged commit 8729091 into main May 25, 2026
1 check passed
@AdamJ AdamJ deleted the fix/archive-stale-closure-refresh branch May 25, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix For general fixes or bundled fixes performance For performance related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant