fix: prevent archived day from reappearing after hard refresh#139
Merged
Conversation
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>
Deploying timetrackerpro with
|
| 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 |
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.
Summary
beforeunloadandhandleBackgroundcaptured stale closure values via theiruseEffect/useCallbackdeps. If the user hard-refreshed immediately after archiving — before React re-rendered and re-registered the handler — the old handler fired withisDayStarted=trueand the pre-archive task list, overwriting the correctly-cleared localStorage entry.latestStateRef.currentinstead of closed-over state vars, eliminating the stale-closure window entirely.archiveDayupdateslatestStateRef.currentsynchronously (before anyawait) so the ref reflects the cleared state the instant the setters are called, not after the next React render.Test plan
🤖 Generated with Claude Code