cogsbox-state 0.5.380 → 0.5.381

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.380",
3
+ "version": "0.5.381",
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
@@ -1907,6 +1907,7 @@ function createProxyHandler<T>(
1907
1907
  setStatus("GETTING_HEIGHTS");
1908
1908
  }
1909
1909
 
1910
+ prevTotalCountRef.current = totalCount;
1910
1911
  prevDepsRef.current = dependencies;
1911
1912
  }, [totalCount, ...dependencies]);
1912
1913
 
@@ -1932,13 +1933,11 @@ function createProxyHandler<T>(
1932
1933
  console.log(
1933
1934
  "ACTION (GETTING_HEIGHTS): Setting range to end and starting loop."
1934
1935
  );
1935
-
1936
1936
  setRange({
1937
1937
  startIndex: Math.max(0, totalCount - 10 - overscan),
1938
1938
  endIndex: totalCount,
1939
1939
  });
1940
1940
 
1941
- let intervalId: NodeJS.Timeout;
1942
1941
  intervalId = setInterval(() => {
1943
1942
  const lastItemIndex = totalCount - 1;
1944
1943
  const shadowArray =
@@ -1950,44 +1949,15 @@ function createProxyHandler<T>(
1950
1949
 
1951
1950
  if (lastItemHeight > 0) {
1952
1951
  clearInterval(intervalId);
1953
-
1954
1952
  if (!shouldNotScroll.current) {
1955
- const prevCount = prevTotalCountRef.current;
1956
- const addedItems = totalCount - prevCount;
1957
- const smallAddition = addedItems > 0 && addedItems <= 3;
1958
-
1959
- if (smallAddition) {
1960
- // Let DOM render before measuring + scrolling
1961
- requestAnimationFrame(() => {
1962
- const prevBottom =
1963
- positions[prevCount] ?? container.scrollHeight;
1964
- const newBottom = container.scrollHeight;
1965
- const delta = newBottom - prevBottom;
1966
-
1967
- if (delta > 0) {
1968
- container.scrollBy({
1969
- top: delta,
1970
- behavior: "smooth",
1971
- });
1972
- }
1973
- prevTotalCountRef.current = totalCount;
1974
-
1975
- console.log(
1976
- "ACTION (GETTING_HEIGHTS): Small addition -> LOCKED_AT_BOTTOM"
1977
- );
1978
- setStatus("LOCKED_AT_BOTTOM");
1979
- });
1980
- } else {
1981
- console.log(
1982
- "ACTION (GETTING_HEIGHTS): Large change -> SCROLLING_TO_BOTTOM"
1983
- );
1984
- setStatus("SCROLLING_TO_BOTTOM");
1985
- }
1953
+ console.log(
1954
+ "ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
1955
+ );
1956
+
1957
+ setStatus("SCROLLING_TO_BOTTOM");
1986
1958
  }
1987
1959
  }
1988
- }, 50);
1989
-
1990
- return () => clearInterval(intervalId);
1960
+ }, 100);
1991
1961
  } else if (status === "SCROLLING_TO_BOTTOM") {
1992
1962
  console.log(
1993
1963
  "ACTION (SCROLLING_TO_BOTTOM): Executing scroll."
@@ -2010,7 +1980,6 @@ function createProxyHandler<T>(
2010
1980
  isProgrammaticScroll.current = false;
2011
1981
  shouldNotScroll.current = false;
2012
1982
  setStatus("LOCKED_AT_BOTTOM");
2013
- prevTotalCountRef.current = totalCount;
2014
1983
  },
2015
1984
  scrollBehavior === "smooth" ? 500 : 50
2016
1985
  );