qstd 0.2.4 → 0.2.5

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 CHANGED
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.5] - 2025-11-25
11
+
12
+ ### Fixed
13
+
14
+ - Fixed `useTheme` hook toggle function not updating `data-theme` attribute
15
+ - Moved localStorage save logic to effect to avoid race condition with event listeners
16
+ - State updates now properly trigger theme changes on HTML element
17
+
10
18
  ## [0.2.4] - 2025-11-24
11
19
 
12
20
  ### Changed
@@ -3588,9 +3588,16 @@ 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 [shouldSave, setShouldSave] = React11__namespace.default.useState(false);
3591
3592
  React11__namespace.default.useEffect(() => {
3592
3593
  document.documentElement.setAttribute("data-theme", store.value);
3593
3594
  }, [store.value]);
3595
+ React11__namespace.default.useEffect(() => {
3596
+ if (shouldSave) {
3597
+ saveStore(store);
3598
+ setShouldSave(false);
3599
+ }
3600
+ }, [store, shouldSave]);
3594
3601
  React11__namespace.default.useEffect(() => {
3595
3602
  const handleStorageChange = (e) => {
3596
3603
  if (e.key === THEME_STORAGE_KEY || e.key === THEME_STORE_STORAGE_KEY) {
@@ -3611,21 +3618,15 @@ function useTheme() {
3611
3618
  };
3612
3619
  }, []);
3613
3620
  const update = (updates) => {
3614
- setStore((prev) => {
3615
- const next = { ...prev, ...updates };
3616
- saveStore(next);
3617
- return next;
3618
- });
3621
+ setStore((prev) => ({ ...prev, ...updates }));
3622
+ setShouldSave(true);
3619
3623
  };
3620
3624
  const toggle = (theme) => {
3621
- setStore((prev) => {
3622
- const next = {
3623
- value: theme ?? (prev.value === "light" ? "dark" : "light"),
3624
- isManual: true
3625
- };
3626
- saveStore(next);
3627
- return next;
3628
- });
3625
+ setStore((prev) => ({
3626
+ value: theme ?? (prev.value === "light" ? "dark" : "light"),
3627
+ isManual: true
3628
+ }));
3629
+ setShouldSave(true);
3629
3630
  };
3630
3631
  return { ...store, update, toggle };
3631
3632
  }
@@ -3565,9 +3565,16 @@ 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 [shouldSave, setShouldSave] = React11__default.useState(false);
3568
3569
  React11__default.useEffect(() => {
3569
3570
  document.documentElement.setAttribute("data-theme", store.value);
3570
3571
  }, [store.value]);
3572
+ React11__default.useEffect(() => {
3573
+ if (shouldSave) {
3574
+ saveStore(store);
3575
+ setShouldSave(false);
3576
+ }
3577
+ }, [store, shouldSave]);
3571
3578
  React11__default.useEffect(() => {
3572
3579
  const handleStorageChange = (e) => {
3573
3580
  if (e.key === THEME_STORAGE_KEY || e.key === THEME_STORE_STORAGE_KEY) {
@@ -3588,21 +3595,15 @@ function useTheme() {
3588
3595
  };
3589
3596
  }, []);
3590
3597
  const update = (updates) => {
3591
- setStore((prev) => {
3592
- const next = { ...prev, ...updates };
3593
- saveStore(next);
3594
- return next;
3595
- });
3598
+ setStore((prev) => ({ ...prev, ...updates }));
3599
+ setShouldSave(true);
3596
3600
  };
3597
3601
  const toggle = (theme) => {
3598
- setStore((prev) => {
3599
- const next = {
3600
- value: theme ?? (prev.value === "light" ? "dark" : "light"),
3601
- isManual: true
3602
- };
3603
- saveStore(next);
3604
- return next;
3605
- });
3602
+ setStore((prev) => ({
3603
+ value: theme ?? (prev.value === "light" ? "dark" : "light"),
3604
+ isManual: true
3605
+ }));
3606
+ setShouldSave(true);
3606
3607
  };
3607
3608
  return { ...store, update, toggle };
3608
3609
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qstd",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Standard Block component and utilities library with Panda CSS",
5
5
  "author": "malin1",
6
6
  "license": "MIT",