Skip to content

feat: cache demo edits in localStorage with Loaded-from-cache banner#18

Merged
shimoncohen merged 8 commits into
mainfrom
feat/example-edit-cache
Jul 21, 2026
Merged

feat: cache demo edits in localStorage with Loaded-from-cache banner#18
shimoncohen merged 8 commits into
mainfrom
feat/example-edit-cache

Conversation

@shimoncohen

@shimoncohen shimoncohen commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Persist user edits to demo examples in localStorage (namespaced key per client/name), auto-saved on change with a configurable debounce.
  • Show an amber "⟳ Loaded from cache" strip over the editor when content is restored from cache, with a Clear cache button (confirm dialog) that discards edits and reloads the original.
  • Plumb the debounce interval end-to-end through Helm: cache.debounceMs → ConfigMap PUBLIC_CACHE_DEBOUNCE_MS$env/dynamic/public → client (500ms fallback).

Changes

  • src/lib/cache/demoCache.ts — localStorage util (cacheKey/loadCache/saveCache/clearCache), SSR-safe, best-effort writes.
  • src/lib/components/flems.svelteonChange prop; registers Flems onchange handler (registrar call, not property assignment).
  • src/routes/demo/[client]/[name]/+page.svelte — reactive cache key (survives same-route demo switches), post-mount load, debounced save, clear-with-confirm, amber banner.
  • helm/values.yaml, helm/templates/configmap.yaml, .env.example — debounce config plumbing.

Test Plan

  • npm run check — 0 errors / 0 warnings
  • npm run build — clean
  • Edit a demo → reload → amber "Loaded from cache" strip appears (needs browser verification — reported not appearing; investigate)
  • Clear cache → confirm → original restored
  • Switch demos via bottom bar → correct example loads
  • Debounce honors PUBLIC_CACHE_DEBOUNCE_MS

🤖 Generated with Claude Code

shimoncohen and others added 7 commits July 20, 2026 14:04
- Call flemsInstance.onchange(fn) instead of assigning it; the Flems
  API exposes onchange as a registrar, so assignment left autosave dead.
- Recompute cache key + reload files reactively on same-route demo
  navigation (component is reused; only data updates).
- Show the 'Loaded from cache' banner only when actually restored from
  cache, not after a fresh-edit autosave.
- Clear pending save timer on demo switch and component destroy; save
  under the key captured at edit time.
- NaN/negative-safe debounce parsing (allows 0); guard localStorage
  writes and drop the unused savedAt field.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shimoncohen shimoncohen self-assigned this Jul 20, 2026
NivGreenstein
NivGreenstein previously approved these changes Jul 21, 2026
Comment thread src/routes/demo/[client]/[name]/+page.svelte Outdated
@shimoncohen
shimoncohen merged commit f7685da into main Jul 21, 2026
5 checks passed
@shimoncohen
shimoncohen deleted the feat/example-edit-cache branch July 21, 2026 08:59
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.

2 participants