thunderbolt icon indicating copy to clipboard operation
thunderbolt copied to clipboard

THU-504: Local settings store

Open raivieiraadriano92 opened this issue 6 months ago • 3 comments

Summary

  • Create a Zustand + localStorage store (local-settings-store.ts) for device-specific settings that shouldn't sync across devices
  • Migrate cloud_url, debug_posthog, is_native_fetch_enabled, haptics_enabled, syncEnabled, and theme from the PowerSync DB / raw localStorage to the new store
  • Remove 5 dead default definitions from defaults/settings.ts and the unused ui-theme DB setting
  • Refactor ThemeProvider to read/write via the Zustand store instead of its own localStorage key
  • Reset local settings to defaults on data deletion to preserve pre-migration cleanup behavior

Why

  • cloud_url creates a bootstrap circular dependency — needed before DB init, but stored in DB
  • is_native_fetch_enabled was read via async DB query on every fetch request — now synchronous
  • Device-specific settings (haptics, native fetch, debug flags) shouldn't sync across devices
  • ui-theme DB setting was dead code — ThemeProvider used its own localStorage
  • powersync_sync_enabled was a scattered raw localStorage flag

Test plan

  • [ ] App starts correctly — cloud_url available at Step 0 without DB
  • [ ] Dev settings page: edit cloud URL, toggle native fetch, toggle debug PostHog — all persist across refresh
  • [ ] Preferences page: haptics toggle works and persists
  • [ ] Theme toggle (light/dark/system) works and persists across refresh
  • [ ] Sync toggle on/off connects/disconnects PowerSync
  • [ ] Chat components using cloudUrl (citations, tool icons, link previews) render correctly
  • [ ] SSO redirect and sign-in form work
  • [ ] Logout → "Delete data from device" resets local settings to defaults
  • [ ] Logout → "Leave data on device" preserves local settings
  • [ ] localStorage has thunderbolt-local-settings key with correct shape
  • [ ] TypeScript compiles with no errors, all tests pass

[!NOTE] Medium Risk Migrates several boot-critical settings (cloudUrl, theme, sync enablement) away from the DB/raw localStorage, which can affect startup, auth redirects, and sync connectivity if defaults or persistence behavior differ.

Overview Introduces a persisted Zustand local-settings-store for device-specific config (cloudUrl, theme, syncEnabled, haptics, native fetch, PostHog debug) and updates callers across AI fetch/evals, auth flows (SSO redirect/sign-in), chat widgets (citations/link previews/tool icons), and PowerSync to read/write from this store instead of DB settings or ad-hoc localStorage keys.

Refactors ThemeProvider and the pre-paint theme script in index.html to use the new persisted store shape, removes several now-dead default DB settings from defaults/settings.ts, and ensures clearLocalData resets local settings back to initialLocalSettings. Tests are updated to seed syncEnabled via the store and to reuse the exported syncEnabledChangeEvent constant.

Reviewed by Cursor Bugbot for commit 6e9b15a486062728be47fd90df06aca583b6aed4. Bugbot is set up for automated code reviews on this repo. Configure here.

raivieiraadriano92 avatar May 11 '26 21:05 raivieiraadriano92

Semgrep Security Scan

No security issues found.

github-actions[bot] avatar May 11 '26 21:05 github-actions[bot]

PR Metrics

Metric Value
Lines changed (prod code) +174 / -176
JS bundle size (gzipped) :green_circle: 1.02 MB → 1.02 MB (-4.0 KB, -0.4%)
Test coverage :yellow_circle: 71.47% → 71.39% (-0.1%)
Performance (preview) Preview not ready — Render deploy may have timed out
Accessibility —
Best Practices —
SEO —

Updated Fri, 15 May 2026 10:09:49 GMT · run #1503

github-actions[bot] avatar May 11 '26 21:05 github-actions[bot]

Preview environment deployed 🚀

Service URL
Marketing / blog / docs https://thunderbolt-pr-857.preview.thunderbolt.io
App https://app-pr-857.preview.thunderbolt.io
API https://api-pr-857.preview.thunderbolt.io
Keycloak https://auth-pr-857.preview.thunderbolt.io
PowerSync https://powersync-pr-857.preview.thunderbolt.io

Stack: preview-pr-857 · Commit: 6e9b15a486062728be47fd90df06aca583b6aed4

Auto-destroys on PR close/merge. Login via the bundled Keycloak realm — [email protected] / demo by default.

github-actions[bot] avatar May 13 '26 21:05 github-actions[bot]