@umituz/react-native-design-system 2.9.64 → 2.9.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-design-system",
3
- "version": "2.9.64",
3
+ "version": "2.9.65",
4
4
  "description": "Universal design system for React Native apps - Consolidated package with atoms, molecules, organisms, theme, typography, responsive, safe area, exception, infinite scroll, UUID, image, timezone, offline, onboarding, and loading utilities",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -29,6 +29,11 @@ interface ThemeActions {
29
29
  initialize: () => Promise<void>;
30
30
  }
31
31
 
32
+ // Mutex to prevent race condition in setThemeMode
33
+ let themeUpdateInProgress = false;
34
+ // Mutex to prevent race condition in initialize
35
+ let themeInitInProgress = false;
36
+
32
37
  /**
33
38
  * Theme Store - Global state management for theme
34
39
  *
@@ -55,6 +60,14 @@ export const useTheme = createStore<ThemeState, ThemeActions>({
55
60
  persist: false,
56
61
  actions: (set, get) => ({
57
62
  initialize: async () => {
63
+ // Atomic check with mutex
64
+ const { isInitialized } = get();
65
+ if (isInitialized || themeInitInProgress) {
66
+ return;
67
+ }
68
+
69
+ themeInitInProgress = true;
70
+
58
71
  try {
59
72
  const savedMode = await ThemeStorage.getThemeMode();
60
73
  if (savedMode) {
@@ -79,25 +92,38 @@ export const useTheme = createStore<ThemeState, ThemeActions>({
79
92
  set({ isInitialized: true });
80
93
  // Ensure design system store is synced even on error
81
94
  useDesignSystemTheme.getState().setThemeMode('dark');
95
+ } finally {
96
+ themeInitInProgress = false;
82
97
  }
83
98
  },
84
99
 
85
100
  setThemeMode: async (mode: ThemeMode) => {
101
+ // Skip if another update is in progress
102
+ if (themeUpdateInProgress) {
103
+ return;
104
+ }
105
+
106
+ themeUpdateInProgress = true;
107
+
86
108
  try {
87
109
  const theme = mode === 'light' ? lightTheme : darkTheme;
88
110
 
111
+ // Set state first
89
112
  set({
90
113
  themeMode: mode,
91
114
  theme,
92
115
  isDark: mode === 'dark',
93
116
  });
94
117
 
118
+ // Then persist (even if this fails, UI is already updated)
95
119
  await ThemeStorage.setThemeMode(mode);
96
120
 
97
121
  // Sync with design system global theme
98
122
  useDesignSystemTheme.getState().setThemeMode(mode);
99
123
  } catch {
100
- // Silent failure
124
+ // Silent failure - UI already updated, just storage failed
125
+ } finally {
126
+ themeUpdateInProgress = false;
101
127
  }
102
128
  },
103
129