cogsbox-state 0.5.308 → 0.5.309

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": "cogsbox-state",
3
- "version": "0.5.308",
3
+ "version": "0.5.309",
4
4
  "description": "React state management library with form controls and server sync",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/CogsState.tsx CHANGED
@@ -1817,6 +1817,20 @@ function createProxyHandler<T>(
1817
1817
  const isAtBottomRef = useRef(stickToBottom);
1818
1818
  const previousTotalCountRef = useRef(0);
1819
1819
  const isInitialMountRef = useRef(true);
1820
+ // Subscribe to shadow state changes
1821
+ const [shadowUpdateTrigger, setShadowUpdateTrigger] = useState(0);
1822
+
1823
+ useEffect(() => {
1824
+ // Subscribe to shadow state updates for this stateKey
1825
+ const unsubscribe = getGlobalStore
1826
+ .getState()
1827
+ .subscribeToShadowState(stateKey, () => {
1828
+ // Force recalculation when shadow state updates
1829
+ setShadowUpdateTrigger((prev) => prev + 1);
1830
+ });
1831
+
1832
+ return unsubscribe;
1833
+ }, [stateKey]);
1820
1834
 
1821
1835
  const sourceArray = getGlobalStore().getNestedState(
1822
1836
  stateKey,
@@ -1840,7 +1854,14 @@ function createProxyHandler<T>(
1840
1854
  }
1841
1855
 
1842
1856
  return { totalHeight: height, positions: pos };
1843
- }, [totalCount, stateKey, path.join("."), itemHeight]);
1857
+ }, [
1858
+ totalCount,
1859
+ stateKey,
1860
+ path.join("."),
1861
+ itemHeight,
1862
+ shadowUpdateTrigger,
1863
+ ]);
1864
+
1844
1865
  console.log("height", totalHeight);
1845
1866
  const virtualState = useMemo(() => {
1846
1867
  const start = Math.max(0, range.startIndex);