Skip to content

fix: Data persistence after session expiry/crash (#40)#13

Merged
ncamaa merged 1 commit intomainfrom
fix/critical-bug-40-persistence
Apr 15, 2026
Merged

fix: Data persistence after session expiry/crash (#40)#13
ncamaa merged 1 commit intomainfrom
fix/critical-bug-40-persistence

Conversation

@ncamaa
Copy link
Copy Markdown
Collaborator

@ncamaa ncamaa commented Apr 15, 2026

Summary

Fixes Critical bug #40 - data not persisting after session expiry or crash.

  • AuthContext.tsx: Added retry logic (3 attempts, exponential backoff) to fetchPlanId(). Exposed authError + retryAuth() for recovery UI. Prevents planId from staying stuck as pending.
  • usePersistentForm.ts: Synchronous localStorage writes for crash safety. 401-aware API save (stops retrying on auth errors). Auto-recovery sync pushes localStorage data to API on re-auth.
  • Tests: Updated to reflect new immediate-write behavior. All 292 tests pass.

Closes codama-dev/clearplan-tickets#40

Test plan

  • All 292 frontend tests pass
  • Enter data, close tab, reopen - data should persist
  • Enter data, let session expire, re-login - data should be recovered
  • Network failure during save - data safe in localStorage, synced on reconnect

- AuthContext: add retry logic (3 attempts with exponential backoff) to
  fetchPlanId so a transient network failure no longer leaves planId
  stuck as null, which disabled all data queries. Expose authError and
  retryAuth so the UI can surface a recovery option.
- usePersistentForm: write to localStorage synchronously on every
  persistValues call (crash-safe backup before debounced API save).
- usePersistentForm: skip retries on 401 errors (session expired) since
  the axios interceptor already redirects to login; data is safe in
  localStorage for the next session.
- usePersistentForm: on mount, if localStorage has newer data than the
  server, schedule an automatic recovery sync to push unsaved data.
@ncamaa ncamaa merged commit 3f3c6f8 into main Apr 15, 2026
6 of 9 checks passed
@ncamaa ncamaa deleted the fix/critical-bug-40-persistence branch April 15, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Data not persisting after session/crash

1 participant