cogsbox-state 0.5.378 → 0.5.379

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.379",
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
@@ -1958,18 +1958,25 @@ function createProxyHandler<T>(
1958
1958
  const smallAddition = addedItems > 0 && addedItems <= 3;
1959
1959
 
1960
1960
  if (smallAddition) {
1961
- const addedHeight =
1962
- positions[totalCount - 1]! -
1963
- (positions[prevCount] ?? 0);
1964
- container.scrollBy({
1965
- top: addedHeight,
1966
- behavior: "smooth",
1967
- });
1961
+ // Let DOM render before measuring + scrolling
1962
+ requestAnimationFrame(() => {
1963
+ const prevBottom =
1964
+ positions[prevCount] ?? container.scrollHeight;
1965
+ const newBottom = container.scrollHeight;
1966
+ const delta = newBottom - prevBottom;
1967
+
1968
+ if (delta > 0) {
1969
+ container.scrollBy({
1970
+ top: delta,
1971
+ behavior: "smooth",
1972
+ });
1973
+ }
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") {