Skip to content

fix: resolve auth race conditions, planned task sync, and destructive UI#186

Merged
AdamJ merged 1 commit into
mainfrom
fix-two-issues
Jun 18, 2026
Merged

fix: resolve auth race conditions, planned task sync, and destructive UI#186
AdamJ merged 1 commit into
mainfrom
fix-two-issues

Conversation

@AdamJ

@AdamJ AdamJ commented Jun 18, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes two categories of issues: auth/sync race conditions that caused planned tasks to be lost or overwritten on login/logout, and several destructive UI styling inconsistencies introduced by the Tailwind v4 migration.

Type of Change

  • Bug fix
  • Update to existing feature

Related Issue

Closes #

Changes Made

Auth / sync race conditions (src/contexts/TimeTrackingContext.tsx, src/services/supabaseService.ts):

  • Consolidated auth-state handling into a single useEffect with an async handleAuthChange; replaced previousAuthState state with prevAuthRef (ref) to avoid extra re-renders
  • On logout: migrateToLocalStorage now runs before setDataService so loadData reads the freshly-written localStorage snapshot instead of racing the migration write
  • todoLoadedRef/plannedLoadedRef reset before setLoading(true) to block mutations against the incoming service until load completes
  • On login: after migrating guest data, planned tasks are reloaded from Supabase so the session reflects what migration wrote
  • migrateFromLocalStorage skips writing planned tasks if Supabase already has any — prevents stale localStorage data (from a previous logout) from overwriting tasks created on another device

ProjectSheet sync (src/components/ProjectSheet.tsx):

  • handleSubmit now awaits forceSyncToDatabase() before closing the sheet — previously the sheet dismissed before sync completed

Destructive UI (src/components/ui/context-menu.tsx, DeleteConfirmationDialog.tsx, ProjectManagement.tsx, PlannedTaskCard.tsx, src/index.css):

  • ContextMenuItem gains a variant prop ("default" | "destructive") — destructive variant applies correct colors at rest and on focus, replacing ad-hoc className overrides
  • Destructive button hover changed from hover:bg-destructive/90 to hover:opacity-90 to avoid Tailwind v4 oklch color-mix issues
  • Delete dialog button order corrected: Cancel now precedes Delete
  • --destructive-foreground CSS token added for both light and dark themes

Checklist

Documentation

  • CHANGELOG.md updated accordingly
  • N/A — no README changes

General

  • Branch is up to date with main
  • No unrelated files included in this PR
  • Tested locally by invoking the pnpm test, pnpm lint, and pnpm build

Notes for Reviewers

The auth race condition fix changes the shape of the auth useEffect significantly — two separate effects collapsed into one. The net behavior is identical for the happy path; the fix closes the window where loadData could fire against the new service before migrateToLocalStorage finished writing.

- Consolidate auth-state handling into single async useEffect; replace
  previousAuthState state with prevAuthRef to avoid extra re-renders
- Run migrateToLocalStorage before setDataService on logout so loadData
  reads the fresh localStorage snapshot instead of racing the write
- Reset todoLoadedRef/plannedLoadedRef before setLoading(true) to block
  mutations against the incoming service until load completes
- After login migration, reload planned tasks from Supabase so the
  session reflects what migration wrote
- migrateFromLocalStorage skips planned tasks if Supabase already has
  any, preventing stale localStorage data from overwriting remote tasks
- ProjectSheet now awaits forceSyncToDatabase before closing
- ContextMenuItem gains variant prop ("default" | "destructive")
- Destructive button hover changed to hover:opacity-90 to avoid Tailwind
  v4 oklch color-mix issues
- Delete dialog button order corrected: Cancel before Delete
- Add --destructive-foreground CSS token to both light and dark themes
- Sync CHANGELOG with all of the above
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 18, 2026

Copy link
Copy Markdown

Deploying timetrackerpro with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7288621
Status: ✅  Deploy successful!
Preview URL: https://6c854253.timetrackerpro.pages.dev
Branch Preview URL: https://fix-two-issues.timetrackerpro.pages.dev

View logs

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jun 18, 2026
@AdamJ AdamJ added this to Timetraked Jun 18, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in Timetraked Jun 18, 2026
This was linked to issues Jun 18, 2026
@AdamJ AdamJ moved this from Backlog to In review in Timetraked Jun 18, 2026
@AdamJ AdamJ added enhancement New feature or request performance For performance related issues labels Jun 18, 2026
@AdamJ AdamJ merged commit 236beb4 into main Jun 18, 2026
3 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in Timetraked Jun 18, 2026
@AdamJ AdamJ deleted the fix-two-issues branch June 18, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request performance For performance related issues

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Bug - Delete Project modal Bug - Delete action planned tasks

1 participant