cogsbox-state 0.5.306 → 0.5.308

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.306",
3
+ "version": "0.5.308",
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,21 +1814,10 @@ function createProxyHandler<T>(
1814
1814
  endIndex: 10,
1815
1815
  });
1816
1816
 
1817
- // Force re-render when heights change
1818
- const [, forceUpdate] = useState({});
1819
-
1820
1817
  const isAtBottomRef = useRef(stickToBottom);
1821
1818
  const previousTotalCountRef = useRef(0);
1822
1819
  const isInitialMountRef = useRef(true);
1823
1820
 
1824
- // Subscribe to shadow state changes
1825
- useEffect(() => {
1826
- const unsubscribe = getGlobalStore
1827
- .getState()
1828
- .subscribeToShadowState(stateKey, () => forceUpdate({}));
1829
- return unsubscribe;
1830
- }, [stateKey]);
1831
-
1832
1821
  const sourceArray = getGlobalStore().getNestedState(
1833
1822
  stateKey,
1834
1823
  path
@@ -1852,7 +1841,7 @@ function createProxyHandler<T>(
1852
1841
 
1853
1842
  return { totalHeight: height, positions: pos };
1854
1843
  }, [totalCount, stateKey, path.join("."), itemHeight]);
1855
-
1844
+ console.log("height", totalHeight);
1856
1845
  const virtualState = useMemo(() => {
1857
1846
  const start = Math.max(0, range.startIndex);
1858
1847
  const end = Math.min(totalCount, range.endIndex);
@@ -1921,25 +1910,21 @@ function createProxyHandler<T>(
1921
1910
 
1922
1911
  // Handle stick to bottom
1923
1912
  if (stickToBottom) {
1924
- if (isInitialMountRef.current && totalCount > 0) {
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
- });
1913
+ if (isInitialMountRef.current) {
1914
+ console.log(
1915
+ "stickToBottom initial mount",
1916
+ container.scrollHeight
1917
+ );
1918
+ container.scrollTo({
1919
+ top: container.scrollHeight,
1920
+ behavior: "auto",
1936
1921
  });
1937
- } else if (
1938
- !isInitialMountRef.current &&
1939
- wasAtBottom &&
1940
- listGrew
1941
- ) {
1942
- // New items added and we were at bottom - stay at bottom
1922
+ isInitialMountRef.current = false;
1923
+ } else if (wasAtBottom && listGrew) {
1924
+ console.log(
1925
+ "stickToBottom wasAtBottom && listGrew",
1926
+ container.scrollHeight
1927
+ );
1943
1928
  requestAnimationFrame(() => {
1944
1929
  container.scrollTo({
1945
1930
  top: container.scrollHeight,
@@ -1948,7 +1933,7 @@ function createProxyHandler<T>(
1948
1933
  });
1949
1934
  }
1950
1935
  }
1951
-
1936
+ console.log("wasAtBottom && listGrew", wasAtBottom, listGrew);
1952
1937
  // Run handleScroll once to set initial range
1953
1938
  handleScroll();
1954
1939