Problem
When the backend goes down while a user has unsaved form input (e.g. profile name, phone number, bio), invalidateAll() triggers the 503 error page which destroys all client-side state. After the backend recovers and the page auto-reloads, the user has to re-enter everything they typed.
Discovered during PR #244 testing — the 503 auto-recovery flow works correctly but is destructive to in-progress work.
Proposed approach
Persist dirty form fields to sessionStorage before the 503 transition and restore them after recovery:
- Create a
$lib/state/form-persistence.svelte.ts utility (e.g. useFormPersistence(key, fields))
- On 503 detection (before
invalidateAll()), snapshot dirty fields to sessionStorage
- On page mount, check for a saved snapshot and restore field values
- Clear the snapshot after successful form submission or on explicit discard
Open questions
- Should this be opt-in per form, or automatic for all forms?
- Should it use
sessionStorage (tab-scoped) or localStorage (persistent)?
- How long should snapshots be retained? TTL-based cleanup?
Affected areas
src/lib/components/profile/ProfileForm.svelte
src/lib/components/settings/ChangePasswordForm.svelte
src/lib/components/admin/ — create/edit dialogs
- Any future forms
Context
Problem
When the backend goes down while a user has unsaved form input (e.g. profile name, phone number, bio),
invalidateAll()triggers the 503 error page which destroys all client-side state. After the backend recovers and the page auto-reloads, the user has to re-enter everything they typed.Discovered during PR #244 testing — the 503 auto-recovery flow works correctly but is destructive to in-progress work.
Proposed approach
Persist dirty form fields to
sessionStoragebefore the 503 transition and restore them after recovery:$lib/state/form-persistence.svelte.tsutility (e.g.useFormPersistence(key, fields))invalidateAll()), snapshot dirty fields tosessionStorageOpen questions
sessionStorage(tab-scoped) orlocalStorage(persistent)?Affected areas
src/lib/components/profile/ProfileForm.sveltesrc/lib/components/settings/ChangePasswordForm.sveltesrc/lib/components/admin/— create/edit dialogsContext
fix/login-session-expired)backend-monitor.tsmiddleware callinginvalidateAll()