cogsbox-state 0.5.304 → 0.5.306

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.304",
3
+ "version": "0.5.306",
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
@@ -1814,10 +1814,21 @@ function createProxyHandler<T>(
1814
1814
  endIndex: 10,
1815
1815
  });
1816
1816
 
1817
+ // Force re-render when heights change
1818
+ const [, forceUpdate] = useState({});
1819
+
1817
1820
  const isAtBottomRef = useRef(stickToBottom);
1818
1821
  const previousTotalCountRef = useRef(0);
1819
1822
  const isInitialMountRef = useRef(true);
1820
1823
 
1824
+ // Subscribe to shadow state changes
1825
+ useEffect(() => {
1826
+ const unsubscribe = getGlobalStore
1827
+ .getState()
1828
+ .subscribeToShadowState(stateKey, () => forceUpdate({}));
1829
+ return unsubscribe;
1830
+ }, [stateKey]);
1831
+
1821
1832
  const sourceArray = getGlobalStore().getNestedState(
1822
1833
  stateKey,
1823
1834
  path
@@ -1911,17 +1922,23 @@ function createProxyHandler<T>(
1911
1922
  // Handle stick to bottom
1912
1923
  if (stickToBottom) {
1913
1924
  if (isInitialMountRef.current && totalCount > 0) {
1914
- // Delay initial scroll to ensure items are rendered
1915
- setTimeout(() => {
1916
- if (containerRef.current) {
1917
- containerRef.current.scrollTo({
1918
- top: containerRef.current.scrollHeight,
1919
- behavior: "auto",
1920
- });
1921
- }
1922
- }, 0);
1923
- isInitialMountRef.current = false;
1924
- } else if (wasAtBottom && listGrew) {
1925
+ // Double rAF to ensure everything is rendered and measured
1926
+ requestAnimationFrame(() => {
1927
+ requestAnimationFrame(() => {
1928
+ if (containerRef.current) {
1929
+ containerRef.current.scrollTo({
1930
+ top: containerRef.current.scrollHeight,
1931
+ behavior: "auto",
1932
+ });
1933
+ isInitialMountRef.current = false;
1934
+ }
1935
+ });
1936
+ });
1937
+ } else if (
1938
+ !isInitialMountRef.current &&
1939
+ wasAtBottom &&
1940
+ listGrew
1941
+ ) {
1925
1942
  // New items added and we were at bottom - stay at bottom
1926
1943
  requestAnimationFrame(() => {
1927
1944
  container.scrollTo({
@@ -1930,8 +1947,6 @@ function createProxyHandler<T>(
1930
1947
  });
1931
1948
  });
1932
1949
  }
1933
- } else {
1934
- isInitialMountRef.current = false;
1935
1950
  }
1936
1951
 
1937
1952
  // Run handleScroll once to set initial range