cogsbox-state 0.5.309 → 0.5.310

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.309",
3
+ "version": "0.5.310",
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
@@ -1817,7 +1817,7 @@ function createProxyHandler<T>(
1817
1817
  const isAtBottomRef = useRef(stickToBottom);
1818
1818
  const previousTotalCountRef = useRef(0);
1819
1819
  const isInitialMountRef = useRef(true);
1820
- // Subscribe to shadow state changes
1820
+ const previousTotalHeightRef = useRef(0);
1821
1821
  const [shadowUpdateTrigger, setShadowUpdateTrigger] = useState(0);
1822
1822
 
1823
1823
  useEffect(() => {
@@ -1883,12 +1883,14 @@ function createProxyHandler<T>(
1883
1883
 
1884
1884
  const wasAtBottom = isAtBottomRef.current;
1885
1885
  const listGrew = totalCount > previousTotalCountRef.current;
1886
+ const heightGrew = totalHeight > previousTotalHeightRef.current;
1886
1887
  previousTotalCountRef.current = totalCount;
1888
+ previousTotalHeightRef.current = totalHeight;
1887
1889
 
1888
1890
  const handleScroll = () => {
1889
1891
  const { scrollTop, clientHeight, scrollHeight } = container;
1890
1892
  isAtBottomRef.current =
1891
- scrollHeight - scrollTop - clientHeight < 10;
1893
+ scrollHeight - scrollTop - clientHeight < 30;
1892
1894
 
1893
1895
  // Binary search for start index
1894
1896
  let low = 0,
@@ -1941,7 +1943,7 @@ function createProxyHandler<T>(
1941
1943
  behavior: "auto",
1942
1944
  });
1943
1945
  isInitialMountRef.current = false;
1944
- } else if (wasAtBottom && listGrew) {
1946
+ } else if (wasAtBottom && (listGrew || heightGrew)) {
1945
1947
  console.log(
1946
1948
  "stickToBottom wasAtBottom && listGrew",
1947
1949
  container.scrollHeight