qstd 0.2.5 → 0.2.6
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/CHANGELOG.md +10 -0
- package/dist/react/index.cjs +20 -14
- package/dist/react/index.js +20 -14
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.6] - 2025-11-25
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Improved `useTheme` hook reliability with refs to prevent stale closures
|
|
15
|
+
- Added `storeRef` to always access current state
|
|
16
|
+
- Added `isInternalUpdateRef` to distinguish internal vs external updates
|
|
17
|
+
- Fixed localStorage parsing to use correct `parsed.value` property
|
|
18
|
+
- Prevents duplicate state updates from custom events
|
|
19
|
+
|
|
10
20
|
## [0.2.5] - 2025-11-25
|
|
11
21
|
|
|
12
22
|
### Fixed
|
package/dist/react/index.cjs
CHANGED
|
@@ -3563,7 +3563,7 @@ var getInitialStore = () => {
|
|
|
3563
3563
|
if (stored) {
|
|
3564
3564
|
const parsed = JSON.parse(stored);
|
|
3565
3565
|
return {
|
|
3566
|
-
value: parsed.
|
|
3566
|
+
value: parsed.value ?? getInitialTheme(),
|
|
3567
3567
|
isManual: parsed.isManual ?? false
|
|
3568
3568
|
};
|
|
3569
3569
|
}
|
|
@@ -3588,16 +3588,14 @@ var saveStore = (store) => {
|
|
|
3588
3588
|
// src/react/use-theme/index.ts
|
|
3589
3589
|
function useTheme() {
|
|
3590
3590
|
const [store, setStore] = React11__namespace.default.useState(getInitialStore);
|
|
3591
|
-
const
|
|
3591
|
+
const storeRef = React11__namespace.default.useRef(store);
|
|
3592
|
+
const isInternalUpdateRef = React11__namespace.default.useRef(false);
|
|
3593
|
+
React11__namespace.default.useEffect(() => {
|
|
3594
|
+
storeRef.current = store;
|
|
3595
|
+
}, [store]);
|
|
3592
3596
|
React11__namespace.default.useEffect(() => {
|
|
3593
3597
|
document.documentElement.setAttribute("data-theme", store.value);
|
|
3594
3598
|
}, [store.value]);
|
|
3595
|
-
React11__namespace.default.useEffect(() => {
|
|
3596
|
-
if (shouldSave) {
|
|
3597
|
-
saveStore(store);
|
|
3598
|
-
setShouldSave(false);
|
|
3599
|
-
}
|
|
3600
|
-
}, [store, shouldSave]);
|
|
3601
3599
|
React11__namespace.default.useEffect(() => {
|
|
3602
3600
|
const handleStorageChange = (e) => {
|
|
3603
3601
|
if (e.key === THEME_STORAGE_KEY || e.key === THEME_STORE_STORAGE_KEY) {
|
|
@@ -3605,6 +3603,10 @@ function useTheme() {
|
|
|
3605
3603
|
}
|
|
3606
3604
|
};
|
|
3607
3605
|
const handleThemeChange = (e) => {
|
|
3606
|
+
if (isInternalUpdateRef.current) {
|
|
3607
|
+
isInternalUpdateRef.current = false;
|
|
3608
|
+
return;
|
|
3609
|
+
}
|
|
3608
3610
|
const customEvent = e;
|
|
3609
3611
|
if (customEvent.detail) {
|
|
3610
3612
|
setStore(customEvent.detail);
|
|
@@ -3618,15 +3620,19 @@ function useTheme() {
|
|
|
3618
3620
|
};
|
|
3619
3621
|
}, []);
|
|
3620
3622
|
const update = (updates) => {
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
+
const newStore = { ...storeRef.current, ...updates };
|
|
3624
|
+
setStore(newStore);
|
|
3625
|
+
isInternalUpdateRef.current = true;
|
|
3626
|
+
saveStore(newStore);
|
|
3623
3627
|
};
|
|
3624
3628
|
const toggle = (theme) => {
|
|
3625
|
-
|
|
3626
|
-
value: theme ?? (
|
|
3629
|
+
const newStore = {
|
|
3630
|
+
value: theme ?? (storeRef.current.value === "light" ? "dark" : "light"),
|
|
3627
3631
|
isManual: true
|
|
3628
|
-
}
|
|
3629
|
-
|
|
3632
|
+
};
|
|
3633
|
+
setStore(newStore);
|
|
3634
|
+
isInternalUpdateRef.current = true;
|
|
3635
|
+
saveStore(newStore);
|
|
3630
3636
|
};
|
|
3631
3637
|
return { ...store, update, toggle };
|
|
3632
3638
|
}
|
package/dist/react/index.js
CHANGED
|
@@ -3540,7 +3540,7 @@ var getInitialStore = () => {
|
|
|
3540
3540
|
if (stored) {
|
|
3541
3541
|
const parsed = JSON.parse(stored);
|
|
3542
3542
|
return {
|
|
3543
|
-
value: parsed.
|
|
3543
|
+
value: parsed.value ?? getInitialTheme(),
|
|
3544
3544
|
isManual: parsed.isManual ?? false
|
|
3545
3545
|
};
|
|
3546
3546
|
}
|
|
@@ -3565,16 +3565,14 @@ var saveStore = (store) => {
|
|
|
3565
3565
|
// src/react/use-theme/index.ts
|
|
3566
3566
|
function useTheme() {
|
|
3567
3567
|
const [store, setStore] = React11__default.useState(getInitialStore);
|
|
3568
|
-
const
|
|
3568
|
+
const storeRef = React11__default.useRef(store);
|
|
3569
|
+
const isInternalUpdateRef = React11__default.useRef(false);
|
|
3570
|
+
React11__default.useEffect(() => {
|
|
3571
|
+
storeRef.current = store;
|
|
3572
|
+
}, [store]);
|
|
3569
3573
|
React11__default.useEffect(() => {
|
|
3570
3574
|
document.documentElement.setAttribute("data-theme", store.value);
|
|
3571
3575
|
}, [store.value]);
|
|
3572
|
-
React11__default.useEffect(() => {
|
|
3573
|
-
if (shouldSave) {
|
|
3574
|
-
saveStore(store);
|
|
3575
|
-
setShouldSave(false);
|
|
3576
|
-
}
|
|
3577
|
-
}, [store, shouldSave]);
|
|
3578
3576
|
React11__default.useEffect(() => {
|
|
3579
3577
|
const handleStorageChange = (e) => {
|
|
3580
3578
|
if (e.key === THEME_STORAGE_KEY || e.key === THEME_STORE_STORAGE_KEY) {
|
|
@@ -3582,6 +3580,10 @@ function useTheme() {
|
|
|
3582
3580
|
}
|
|
3583
3581
|
};
|
|
3584
3582
|
const handleThemeChange = (e) => {
|
|
3583
|
+
if (isInternalUpdateRef.current) {
|
|
3584
|
+
isInternalUpdateRef.current = false;
|
|
3585
|
+
return;
|
|
3586
|
+
}
|
|
3585
3587
|
const customEvent = e;
|
|
3586
3588
|
if (customEvent.detail) {
|
|
3587
3589
|
setStore(customEvent.detail);
|
|
@@ -3595,15 +3597,19 @@ function useTheme() {
|
|
|
3595
3597
|
};
|
|
3596
3598
|
}, []);
|
|
3597
3599
|
const update = (updates) => {
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
+
const newStore = { ...storeRef.current, ...updates };
|
|
3601
|
+
setStore(newStore);
|
|
3602
|
+
isInternalUpdateRef.current = true;
|
|
3603
|
+
saveStore(newStore);
|
|
3600
3604
|
};
|
|
3601
3605
|
const toggle = (theme) => {
|
|
3602
|
-
|
|
3603
|
-
value: theme ?? (
|
|
3606
|
+
const newStore = {
|
|
3607
|
+
value: theme ?? (storeRef.current.value === "light" ? "dark" : "light"),
|
|
3604
3608
|
isManual: true
|
|
3605
|
-
}
|
|
3606
|
-
|
|
3609
|
+
};
|
|
3610
|
+
setStore(newStore);
|
|
3611
|
+
isInternalUpdateRef.current = true;
|
|
3612
|
+
saveStore(newStore);
|
|
3607
3613
|
};
|
|
3608
3614
|
return { ...store, update, toggle };
|
|
3609
3615
|
}
|