Skip to content

refactor(settings): optimize Zustand selectors and enforce strict Set…#442

Merged
RUKAYAT-CODER merged 2 commits into
rinafcode:mainfrom
AlphaMaleBaDI:fix/zustand-selector-optimization
May 28, 2026
Merged

refactor(settings): optimize Zustand selectors and enforce strict Set…#442
RUKAYAT-CODER merged 2 commits into
rinafcode:mainfrom
AlphaMaleBaDI:fix/zustand-selector-optimization

Conversation

@AlphaMaleBaDI
Copy link
Copy Markdown

Closes #220

Summary

This PR optimizes the application's Zustand store subscriptions by replacing broad store destructuring with granular, field-specific selectors to minimize component re-renders. Additionally, it strengthens the type safety boundaries of the mobile settings selection UI.

Changes Made

  • Granular Store Subscriptions: Implemented dedicated selector hooks in src/store/selectors.ts for individual state fields (useTheme, useUser, useIsAuthenticated, etc.) and a reference-stable hook for action dispatchers (useAppActions).
  • Type-Generic Selection Component: Refactored SettingsPicker to be generic (SettingsPicker<T extends string>), allowing string union types like ProfileVisibility, DownloadQuality, and "light" | "dark" to propagate natively without type assertions or generic string leaks.
  • Mobile Settings Integration: Updated MobileSettings and settings pages to consume the new granular hooks and use strictly typed options lists.

Performance Impact

  • Reduced Render Footprints: Components now only re-render when the exact state slices they depend on change. Changing the theme or a global loading state no longer triggers full re-render cycles across unaffected settings panels.
  • Stable Dispatch Actions: Bypassed the use of legacy shallow functions in the actions hook, improving compatibility and avoiding unnecessary updates since store actions maintain reference stability across renders.

Notes

While verifying these optimizations locally, several unrelated native module compilation warnings and Expo Go environment exceptions were encountered (involving react-native-nitro-modules, expo-dev-client, and expo-barcode-scanner). These are pre-existing upstream repository issues and do not impact or relate to the store optimization changes introduced in this PR.

Verification

  • TypeScript compilation verified with npx tsc --noEmit
  • Zustand selector subscriptions narrowed to granular state slices
  • Mobile settings flows updated to use strict typed picker values

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 27, 2026

@AlphaMaleBaDI 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

@RUKAYAT-CODER
Copy link
Copy Markdown
Contributor

kindly resolve conflict and fix workflow.

@AlphaMaleBaDI
Copy link
Copy Markdown
Author

Conflicts with upstream main have been resolved and the branch has been synchronized successfully. The selector optimizations and strict type-safety changes were preserved while integrating the latest upstream updates. TypeScript verification was also re-run locally after reconciliation.

@RUKAYAT-CODER
Copy link
Copy Markdown
Contributor

LGTM. thank you for your contribution.

@RUKAYAT-CODER RUKAYAT-CODER merged commit 43a8858 into rinafcode:main May 28, 2026
1 of 4 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.

Optimize Zustand store selectors to prevent unnecessary re-renders

2 participants