cogsbox-state 0.5.324 → 0.5.326

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.324",
3
+ "version": "0.5.326",
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
@@ -1871,7 +1871,29 @@ function createProxyHandler<T>(
1871
1871
  validIndices,
1872
1872
  });
1873
1873
  }, [range.startIndex, range.endIndex, sourceArray, totalCount]);
1874
+ useEffect(() => {
1875
+ if (stickToBottom && totalCount > 0 && containerRef.current) {
1876
+ // When count increases, immediately adjust range to show bottom
1877
+ const container = containerRef.current;
1878
+ const visibleCount = Math.ceil(
1879
+ container.clientHeight / itemHeight
1880
+ );
1881
+
1882
+ // Set range to show the last items including the new one
1883
+ setRange({
1884
+ startIndex: Math.max(
1885
+ 0,
1886
+ totalCount - visibleCount - overscan
1887
+ ),
1888
+ endIndex: totalCount,
1889
+ });
1874
1890
 
1891
+ // Then scroll to bottom after a short delay
1892
+ setTimeout(() => {
1893
+ container.scrollTop = container.scrollHeight;
1894
+ }, 100);
1895
+ }
1896
+ }, [totalCount]);
1875
1897
  // This is the main effect that handles all scrolling and updates.
1876
1898
  useLayoutEffect(() => {
1877
1899
  const container = containerRef.current;
@@ -1922,11 +1944,10 @@ function createProxyHandler<T>(
1922
1944
  // We use a timeout to wait for React to render AND for useMeasure to update heights.
1923
1945
  // This is the CRUCIAL part that fixes the race condition.
1924
1946
  scrollTimeoutId = setTimeout(() => {
1925
- // By the time this runs, `container.scrollHeight` is accurate.
1926
- // We only scroll if the user hasn't manually scrolled up in the meantime.
1947
+ console.log("totalHeight", totalHeight);
1927
1948
  if (isLockedToBottomRef.current) {
1928
1949
  container.scrollTo({
1929
- top: container.scrollHeight,
1950
+ top: 999999999,
1930
1951
  behavior: "auto", // ALWAYS 'auto' for an instant, correct jump.
1931
1952
  });
1932
1953
  }
@@ -1941,7 +1962,7 @@ function createProxyHandler<T>(
1941
1962
  container.removeEventListener("scroll", handleUserScroll);
1942
1963
  };
1943
1964
  // This effect re-runs whenever the list size or item heights change.
1944
- }, [totalCount, positions, stickToBottom]);
1965
+ }, [totalCount, positions, totalHeight, stickToBottom]);
1945
1966
 
1946
1967
  const scrollToBottom = useCallback(
1947
1968
  (behavior: ScrollBehavior = "smooth") => {