Skip to content

Persisted state store with migrations, export and import - #23

Merged
ToothyDev merged 1 commit into
mainfrom
claude/issue-1-5sz08c
Oct 13, 2026
Merged

ToothyDev merged 1 commit into
mainfrom
claude/issue-1-5sz08c

Conversation

@ToothyDev

Copy link
Copy Markdown
Owner

What this does

Adds the one place where all user state lives: a versioned root state saved to a single localStorage key (lsos:state). Writes are debounced (500 ms) and flushed on pagehide. Older versions migrate step by step on load. Newer or unreadable stored data is never overwritten: a warning shows and the data can be exported as it is. If storage is missing or full, LSOS keeps working in memory and shows a warning. The Settings tab gets Export and Import buttons, and imports are validated with clear error messages.

  • src/lib/state.ts: AppState (no sections yet), parseState, migrate, exportFileName
  • src/lib/persistence.ts: storage, debounce with an injected scheduler, status (saved / memory / blocked)
  • src/lib/store.svelte.ts: thin Svelte 5 wiring ($state store, $effect → save, pagehide)
  • src/components/Settings.svelte, src/components/SaveStatus.svelte
  • Decision 007 records the non-obvious choices (unreadable data blocks like a newer version; only an import gets past a block).

Follow-up: #22 (two open tabs overwrite each other's saves).

Closes #1

How to check it

  • Settings tab → Export downloads lsos-backup-<date>.json containing {"version":1}.
  • Import a file like {"hello":1} → "Could not import …: it has no valid version number."
  • In devtools, localStorage.setItem('lsos:state', '{"version":99}') and reload → orange warning; Export gives back exactly that text; the stored value stays untouched. Importing a valid file (after the confirm dialog) replaces it and the warning goes away.
  • Private window / blocked site data → "Browser storage is not available" warning, app still works.

Checklist

  • npm run verify passes
  • Game data added or changed here has a source (see docs/decisions/004-game-data.md) (none added)
  • README / CLAUDE.md updated if usage or workflow changed

🤖 Generated with Claude Code


Generated by Claude Code

Versioned root state saved to one localStorage key with debounced writes
and a flush on pagehide. Older versions migrate step by step; newer or
unreadable data is never overwritten and can be exported as it is.
Storage that is missing or full falls back to memory with a warning.
The Settings tab gets Export and Import buttons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying lsos with  Cloudflare Pages  Cloudflare Pages

Latest commit: baa1986
Status: ✅  Deploy successful!
Preview URL: https://8ea4638d.lsos-2qs.pages.dev
Branch Preview URL: https://claude-issue-1-5sz08c.lsos-2qs.pages.dev

View logs

@ToothyDev
ToothyDev merged commit 81bcc19 into main Oct 13, 2026
4 of 5 checks passed
@ToothyDev
ToothyDev deleted the claude/issue-1-5sz08c branch October 13, 2026 21:38
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.

Core: persisted state store (versioned localStorage, migrations, export/import)

2 participants