Skip to content

Feat/optimize zustand store initial state#449

Open
Imole203 wants to merge 3 commits into
rinafcode:mainfrom
Imole203:feat/optimize-zustand-store-initial-state
Open

Feat/optimize zustand store initial state#449
Imole203 wants to merge 3 commits into
rinafcode:mainfrom
Imole203:feat/optimize-zustand-store-initial-state

Conversation

@Imole203
Copy link
Copy Markdown

perf: Optimize Zustand store initial state to reduce memory footprint

Summary

Audited all Zustand stores and removed two sources of unnecessary eager
initialization at startup.

Changes

  • store/index.ts — Removed barrel re-exports of notificationStore,
    courseProgressStore, and uiStore. These caused all three stores to be
    instantiated the moment useAppStore was imported (e.g. in auth.ts), even when
    only auth state was needed. Each store is now initialized on-demand when first
    imported by a consumer.
  • store/settingsStore.ts — Removed the dead DEFAULT_SETTINGS constant (a
    15-field object that duplicated INITIAL_STATE but was never referenced
    anywhere).

What was already correct

  • achievementStore already lazy-initializes DEFAULT_ACHIEVEMENTS via
    loadAchievements() — store starts with achievements: []
  • quizStore loads progress on demand via loadQuizProgress(courseId)
  • All consumers already import directly from individual store files — no import
    updates required

Testing

All 115 existing tests pass across 6 suites (notificationStore, settingsStore,
quizStore, auth, store).

Closes #262

Imole203 added 2 commits May 28, 2026 00:30
- Extract theme into useUiStore (AsyncStorage, not SecureStore)
- Remove theme/setTheme from useAppStore; appStore is now auth-only
- Lazy-initialize achievementStore: start with [] and seed defaults
  on first loadAchievements() call instead of at store creation
- Update useAdaptiveTheme, MobileSettings, Settings to use useUiStore
- Update tests/store.test.ts setTheme suite to target useUiStore
- Fix pre-existing ESLint import/order and component-definition warnings

Closes rinafcode#5 rinafcode#6 rinafcode#29
- Remove barrel re-exports from store/index.ts (notificationStore,
  courseProgressStore, uiStore) to prevent eager initialization when
  only useAppStore is needed
- Remove dead DEFAULT_SETTINGS constant in settingsStore (duplicate
  of INITIAL_STATE, never referenced)
@RUKAYAT-CODER
Copy link
Copy Markdown
Contributor

Kindly resolve conflict and workflow.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 28, 2026

@Imole203 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Reduce initial state object size in Zustand store

2 participants