cogsbox-state 0.5.416 → 0.5.418

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.416",
3
+ "version": "0.5.418",
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
@@ -1823,7 +1823,7 @@ function createProxyHandler<T>(
1823
1823
  const [shadowUpdateTrigger, setShadowUpdateTrigger] = useState(0);
1824
1824
  const wasAtBottomRef = useRef(true);
1825
1825
  const previousCountRef = useRef(0);
1826
-
1826
+ const userHasScrolledAwayRef = useRef(false);
1827
1827
  // Subscribe to shadow state updates
1828
1828
  useEffect(() => {
1829
1829
  const unsubscribe = getGlobalStore
@@ -1909,10 +1909,15 @@ function createProxyHandler<T>(
1909
1909
  const isInitialLoad =
1910
1910
  previousCountRef.current === 0 && totalCount > 0;
1911
1911
 
1912
- if ((hasNewItems || isInitialLoad) && wasAtBottomRef.current) {
1912
+ // Only auto-scroll if we haven't scrolled away AND we're at bottom
1913
+ if (
1914
+ (hasNewItems || isInitialLoad) &&
1915
+ wasAtBottomRef.current &&
1916
+ !userHasScrolledAwayRef.current
1917
+ ) {
1913
1918
  // First, ensure the last items are in range
1914
1919
  const visibleCount = Math.ceil(
1915
- containerRef.current?.clientHeight || 0 / itemHeight
1920
+ (containerRef.current?.clientHeight || 0) / itemHeight
1916
1921
  );
1917
1922
  const newRange = {
1918
1923
  startIndex: Math.max(
@@ -1935,7 +1940,6 @@ function createProxyHandler<T>(
1935
1940
  }, 50);
1936
1941
 
1937
1942
  previousCountRef.current = totalCount;
1938
-
1939
1943
  return () => clearTimeout(timeoutId);
1940
1944
  }
1941
1945
 
@@ -1952,8 +1956,19 @@ function createProxyHandler<T>(
1952
1956
  const distanceFromBottom =
1953
1957
  scrollHeight - scrollTop - clientHeight;
1954
1958
 
1955
- // Track if we're at bottom (with tolerance)
1956
- wasAtBottomRef.current = distanceFromBottom < 100;
1959
+ // Track if user is at bottom with tight tolerance
1960
+ const isAtBottom = distanceFromBottom < 5;
1961
+ wasAtBottomRef.current = isAtBottom;
1962
+
1963
+ // If user scrolls away from bottom, set the flag
1964
+ if (!isAtBottom && distanceFromBottom > 50) {
1965
+ userHasScrolledAwayRef.current = true;
1966
+ }
1967
+
1968
+ // If user scrolls back to bottom, clear the flag
1969
+ if (isAtBottom) {
1970
+ userHasScrolledAwayRef.current = false;
1971
+ }
1957
1972
 
1958
1973
  // Update visible range based on scroll position
1959
1974
  let startIndex = 0;
@@ -1978,7 +1993,6 @@ function createProxyHandler<T>(
1978
1993
  endIndex: Math.min(totalCount, endIndex + 1 + overscan),
1979
1994
  });
1980
1995
  };
1981
-
1982
1996
  container.addEventListener("scroll", handleScroll, {
1983
1997
  passive: true,
1984
1998
  });