cogsbox-state 0.5.307 → 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.307",
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,9 @@ 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
- const previousTotalHeightRef = useRef(0);
1824
-
1825
- // Subscribe to shadow state changes
1826
- useEffect(() => {
1827
- const unsubscribe = getGlobalStore
1828
- .getState()
1829
- .subscribeToShadowState(stateKey, () => forceUpdate({}));
1830
- return unsubscribe;
1831
- }, [stateKey]);
1832
1820
 
1833
1821
  const sourceArray = getGlobalStore().getNestedState(
1834
1822
  stateKey,
@@ -1853,29 +1841,7 @@ function createProxyHandler<T>(
1853
1841
 
1854
1842
  return { totalHeight: height, positions: pos };
1855
1843
  }, [totalCount, stateKey, path.join("."), itemHeight]);
1856
-
1857
- // Adjust scroll when height changes while at bottom
1858
- useLayoutEffect(() => {
1859
- const container = containerRef.current;
1860
- if (!container) return;
1861
-
1862
- const heightChanged =
1863
- totalHeight !== previousTotalHeightRef.current;
1864
- previousTotalHeightRef.current = totalHeight;
1865
-
1866
- // If we're at bottom and height changed, maintain bottom position
1867
- if (
1868
- heightChanged &&
1869
- isAtBottomRef.current &&
1870
- !isInitialMountRef.current
1871
- ) {
1872
- container.scrollTo({
1873
- top: container.scrollHeight,
1874
- behavior: "auto",
1875
- });
1876
- }
1877
- }, [totalHeight]);
1878
-
1844
+ console.log("height", totalHeight);
1879
1845
  const virtualState = useMemo(() => {
1880
1846
  const start = Math.max(0, range.startIndex);
1881
1847
  const end = Math.min(totalCount, range.endIndex);
@@ -1942,38 +1908,32 @@ function createProxyHandler<T>(
1942
1908
  passive: true,
1943
1909
  });
1944
1910
 
1945
- // Handle stick to bottom for initial mount only
1946
- if (
1947
- stickToBottom &&
1948
- isInitialMountRef.current &&
1949
- totalCount > 0
1950
- ) {
1951
- // Set flag first to prevent height adjustment from interfering
1952
- isAtBottomRef.current = true;
1953
- // Wait for next frame to ensure everything is rendered
1954
- requestAnimationFrame(() => {
1955
- if (containerRef.current) {
1956
- containerRef.current.scrollTo({
1957
- top: containerRef.current.scrollHeight,
1958
- behavior: "auto",
1959
- });
1960
- isInitialMountRef.current = false;
1961
- }
1962
- });
1963
- } else if (
1964
- !isInitialMountRef.current &&
1965
- wasAtBottom &&
1966
- listGrew
1967
- ) {
1968
- // New items added and we were at bottom - stay at bottom
1969
- requestAnimationFrame(() => {
1911
+ // Handle stick to bottom
1912
+ if (stickToBottom) {
1913
+ if (isInitialMountRef.current) {
1914
+ console.log(
1915
+ "stickToBottom initial mount",
1916
+ container.scrollHeight
1917
+ );
1970
1918
  container.scrollTo({
1971
1919
  top: container.scrollHeight,
1972
- behavior: "smooth",
1920
+ behavior: "auto",
1973
1921
  });
1974
- });
1922
+ isInitialMountRef.current = false;
1923
+ } else if (wasAtBottom && listGrew) {
1924
+ console.log(
1925
+ "stickToBottom wasAtBottom && listGrew",
1926
+ container.scrollHeight
1927
+ );
1928
+ requestAnimationFrame(() => {
1929
+ container.scrollTo({
1930
+ top: container.scrollHeight,
1931
+ behavior: "smooth",
1932
+ });
1933
+ });
1934
+ }
1975
1935
  }
1976
-
1936
+ console.log("wasAtBottom && listGrew", wasAtBottom, listGrew);
1977
1937
  // Run handleScroll once to set initial range
1978
1938
  handleScroll();
1979
1939