Skip to content

fix: stop SettingsPage crashing on cold load#656

Merged
Mng-dev-ai merged 1 commit into
mainfrom
fix/settings-page-cold-load-crash
Jun 21, 2026
Merged

fix: stop SettingsPage crashing on cold load#656
Mng-dev-ai merged 1 commit into
mainfrom
fix/settings-page-cold-load-crash

Conversation

@Mng-dev-ai

Copy link
Copy Markdown
Owner

Summary

  • On a hard refresh of the Settings page, there's exactly one render where the query's settings have resolved (so loading is false) but the useEffect that syncs localSettings hasn't fired yet — leaving localSettings === null.
  • That render crashed two ways: the post-gate invariant throw'd, and hasUnsavedChanges dereferenced the null localSettings via buildChangedPayload (null is not an object).
  • Guard hasUnsavedChanges against null localSettings, and replace the post-gate throw with the loading spinner so the page waits one render for the sync effect.
  • Consolidate the now-redundant if (loading) branch into the single !settings || !localSettings spinner gate (isLoading is only true when there's no data yet), dropping the unused loading binding.
  • Kept the useEffect sync rather than a render-time ref check — localSettings is settings-form state (a copy of server data the user edits independently), which CLAUDE.md designates as the correct case for effect-based syncing.

Test plan

  • Hard-refresh on /settings (each tab) — page loads without crashing
  • Navigate to /settings from a warm cache — no spinner flash, content renders immediately
  • Edit a field, confirm the unsaved-changes banner appears and Save/Discard work
  • Simulate a settings fetch failure — "Failed to load settings" still shows

On a hard refresh, there's one render where the query's settings have
resolved but the effect syncing localSettings hasn't run yet. The old
post-gate invariant threw on that render, and hasUnsavedChanges
dereferenced a null localSettings. Guard both paths and show the
loading spinner until localSettings is populated.
@Mng-dev-ai Mng-dev-ai marked this pull request as ready for review June 21, 2026 15:42
@Mng-dev-ai Mng-dev-ai merged commit e6ba189 into main Jun 21, 2026
2 checks passed
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.

1 participant