THU-504: Local settings store
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, andthemefrom the PowerSync DB / raw localStorage to the new store - Remove 5 dead default definitions from
defaults/settings.tsand the unusedui-themeDB setting - Refactor
ThemeProviderto 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_urlcreates a bootstrap circular dependency — needed before DB init, but stored in DBis_native_fetch_enabledwas 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-themeDB setting was dead code —ThemeProviderused its own localStoragepowersync_sync_enabledwas a scattered raw localStorage flag
Test plan
- [ ] App starts correctly —
cloud_urlavailable 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
- [ ]
localStoragehasthunderbolt-local-settingskey 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/rawlocalStorage, which can affect startup, auth redirects, and sync connectivity if defaults or persistence behavior differ.Overview Introduces a persisted Zustand
local-settings-storefor 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-hoclocalStoragekeys.Refactors
ThemeProviderand the pre-paint theme script inindex.htmlto use the new persisted store shape, removes several now-dead default DB settings fromdefaults/settings.ts, and ensuresclearLocalDataresets local settings back toinitialLocalSettings. Tests are updated to seedsyncEnabledvia the store and to reuse the exportedsyncEnabledChangeEventconstant.Reviewed by Cursor Bugbot for commit 6e9b15a486062728be47fd90df06aca583b6aed4. Bugbot is set up for automated code reviews on this repo. Configure here.
Semgrep Security Scan
No security issues found.
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
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.