Skip to content

[Enhancement] Add hydration error recovery for all Zustand persisted stores #679

Description

@RUKAYAT-CODER

Overview

Zustand persist middleware rehydrates state from AsyncStorage on startup. If the stored JSON is malformed (truncated write, encoding error, schema version mismatch), JSON.parse throws and the store initializes with undefined state instead of initialState defaults. Components immediately crash with cannot-read-undefined errors. No recovery mechanism exists.

Specifications

Features:

  • All persisted stores provide onRehydrateStorage error callback resetting to initialState
  • Hydration error logged to appLogger.warn with store name
  • Sentry receives warning event with store name after hydration failure
  • User sees one-time toast after reset: 'Your preferences were reset'

Tasks:

  • Add onRehydrateStorage: () => (state, error) => { if (error) { set(initialState); appLogger.warn(...); } } to all persist configs
  • Report to Sentry in error branch with store name
  • Show toast on next render after any hydration error
  • Add unit tests: malformed JSON input to each store verifies default state
  • Include in Zustand store factory (from store factory issue)

Impacted Files:

  • All src/store/slices/*.ts files
  • src/store/createStore.ts (if store factory created)

Acceptance Criteria

  • Malformed AsyncStorage JSON causes store to use default state, not crash
  • Hydration error logged and sent to Sentry
  • User notified with toast when any store resets to defaults
  • Unit tests confirm default state on corrupted input for at least 3 stores

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't workingenhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions