Skip to content

THU-504: Local settings store#857

Open
raivieiraadriano92 wants to merge 13 commits into
mainfrom
raivieiraadriano92/thu-504-local-settings-store
Open

THU-504: Local settings store#857
raivieiraadriano92 wants to merge 13 commits into
mainfrom
raivieiraadriano92/thu-504-local-settings-store

Conversation

@raivieiraadriano92
Copy link
Copy Markdown
Collaborator

@raivieiraadriano92 raivieiraadriano92 commented May 11, 2026

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 6e9b15a. Bugbot is set up for automated code reviews on this repo. Configure here.

@raivieiraadriano92 raivieiraadriano92 self-assigned this May 11, 2026
@raivieiraadriano92 raivieiraadriano92 changed the title Raivieiraadriano92/thu 504 local settings store THU-504: Local settings store May 11, 2026
@github-actions
Copy link
Copy Markdown

Semgrep Security Scan

No security issues found.

@raivieiraadriano92 raivieiraadriano92 marked this pull request as ready for review May 11, 2026 21:55
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 11, 2026

PR Metrics

Metric Value
Lines changed (prod code) +174 / -176
JS bundle size (gzipped) 🟢 1.02 MB → 1.02 MB (-4.0 KB, -0.4%)
Test coverage 🟡 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

Comment thread src/components/chat/tool-icon.tsx
Copy link
Copy Markdown
Collaborator

@ital0 ital0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pointed out some details I noticed.

I completetly ignore files under eval since they should be used only internally.

Comment thread src/stores/local-settings-store.ts Outdated
Comment thread src/db/powersync/database.ts
Comment thread src/lib/theme-provider.tsx Outdated
Comment thread src/stores/local-settings-store.ts Outdated
Comment thread src/components/chat/citation-badge.tsx Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

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 — demo@thunderbolt.io / demo by default.

Comment thread src/settings/dev-settings.tsx Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 36983cb. Configure here.

Comment thread src/stores/local-settings-store.ts
Comment thread src/db/powersync/database.ts
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