cogsbox-state 0.5.378 → 0.5.380

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.378",
3
+ "version": "0.5.380",
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,7 +1907,6 @@ function createProxyHandler<T>(
1907
1907
  setStatus("GETTING_HEIGHTS");
1908
1908
  }
1909
1909
 
1910
- prevTotalCountRef.current = totalCount;
1911
1910
  prevDepsRef.current = dependencies;
1912
1911
  }, [totalCount, ...dependencies]);
1913
1912
 
@@ -1958,18 +1957,26 @@ function createProxyHandler<T>(
1958
1957
  const smallAddition = addedItems > 0 && addedItems <= 3;
1959
1958
 
1960
1959
  if (smallAddition) {
1961
- const addedHeight =
1962
- positions[totalCount - 1]! -
1963
- (positions[prevCount] ?? 0);
1964
- container.scrollBy({
1965
- top: addedHeight,
1966
- behavior: "smooth",
1967
- });
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;
1968
1974
 
1969
- console.log(
1970
- "ACTION (GETTING_HEIGHTS): Small addition -> LOCKED_AT_BOTTOM"
1971
- );
1972
- setStatus("LOCKED_AT_BOTTOM");
1975
+ console.log(
1976
+ "ACTION (GETTING_HEIGHTS): Small addition -> LOCKED_AT_BOTTOM"
1977
+ );
1978
+ setStatus("LOCKED_AT_BOTTOM");
1979
+ });
1973
1980
  } else {
1974
1981
  console.log(
1975
1982
  "ACTION (GETTING_HEIGHTS): Large change -> SCROLLING_TO_BOTTOM"
@@ -1978,7 +1985,7 @@ function createProxyHandler<T>(
1978
1985
  }
1979
1986
  }
1980
1987
  }
1981
- }, 100);
1988
+ }, 50);
1982
1989
 
1983
1990
  return () => clearInterval(intervalId);
1984
1991
  } else if (status === "SCROLLING_TO_BOTTOM") {
@@ -2003,6 +2010,7 @@ function createProxyHandler<T>(
2003
2010
  isProgrammaticScroll.current = false;
2004
2011
  shouldNotScroll.current = false;
2005
2012
  setStatus("LOCKED_AT_BOTTOM");
2013
+ prevTotalCountRef.current = totalCount;
2006
2014
  },
2007
2015
  scrollBehavior === "smooth" ? 500 : 50
2008
2016
  );