cogsbox-state 0.5.423 → 0.5.424

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.423",
3
+ "version": "0.5.424",
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
@@ -1824,7 +1824,7 @@ function createProxyHandler<T>(
1824
1824
  const wasAtBottomRef = useRef(true);
1825
1825
  const userHasScrolledAwayRef = useRef(false);
1826
1826
  const previousCountRef = useRef(0);
1827
-
1827
+ const lastRangeRef = useRef(range);
1828
1828
  // Subscribe to shadow state updates
1829
1829
  useEffect(() => {
1830
1830
  const unsubscribe = getGlobalStore
@@ -1956,7 +1956,7 @@ function createProxyHandler<T>(
1956
1956
  userHasScrolledAwayRef.current = true;
1957
1957
  }
1958
1958
 
1959
- // If user scrolls back to bottom, clear flag
1959
+ // If user scrolls back to bottom, cle
1960
1960
  if (distanceFromBottom < 5) {
1961
1961
  userHasScrolledAwayRef.current = false;
1962
1962
  }
@@ -1979,10 +1979,26 @@ function createProxyHandler<T>(
1979
1979
  endIndex = i;
1980
1980
  }
1981
1981
 
1982
- setRange({
1983
- startIndex: Math.max(0, startIndex),
1984
- endIndex: Math.min(totalCount, endIndex + 1 + overscan),
1985
- });
1982
+ const newStartIndex = Math.max(0, startIndex);
1983
+ const newEndIndex = Math.min(
1984
+ totalCount,
1985
+ endIndex + 1 + overscan
1986
+ );
1987
+
1988
+ // THE FIX: Only update state if the visible range of items has changed.
1989
+ if (
1990
+ newStartIndex !== lastRangeRef.current.startIndex ||
1991
+ newEndIndex !== lastRangeRef.current.endIndex
1992
+ ) {
1993
+ lastRangeRef.current = {
1994
+ startIndex: newStartIndex,
1995
+ endIndex: newEndIndex,
1996
+ };
1997
+ setRange({
1998
+ startIndex: newStartIndex,
1999
+ endIndex: newEndIndex,
2000
+ });
2001
+ }
1986
2002
  };
1987
2003
 
1988
2004
  container.addEventListener("scroll", handleScroll, {