cogsbox-state 0.5.354 → 0.5.356

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.354",
3
+ "version": "0.5.356",
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
@@ -1816,7 +1816,7 @@ function createProxyHandler<T>(
1816
1816
  });
1817
1817
 
1818
1818
  const isLockedToBottomRef = useRef(stickToBottom);
1819
-
1819
+ const isAutoScrolling = useRef(false);
1820
1820
  const [shadowUpdateTrigger, setShadowUpdateTrigger] = useState(0);
1821
1821
 
1822
1822
  useEffect(() => {
@@ -1915,12 +1915,15 @@ function createProxyHandler<T>(
1915
1915
  "color: green; font-weight: bold;"
1916
1916
  );
1917
1917
  clearInterval(intervalId); // Stop the loop.
1918
-
1918
+ isAutoScrolling.current = true;
1919
1919
  // STEP 3: Scroll.
1920
1920
  container.scrollTo({
1921
1921
  top: container.scrollHeight,
1922
1922
  behavior: "smooth",
1923
1923
  });
1924
+ setTimeout(() => {
1925
+ isAutoScrolling.current = false;
1926
+ }, 1000);
1924
1927
  } else {
1925
1928
  console.log("...WAITING. Height is not ready.");
1926
1929
  if (loopCount > 20) {
@@ -1933,12 +1936,11 @@ function createProxyHandler<T>(
1933
1936
  }
1934
1937
  }, 100); // Check every 100ms.
1935
1938
 
1936
- // Cleanup: Stop the loop if the component unmounts.
1937
1939
  return () => {
1938
1940
  console.log("ALGORITHM: Cleaning up loop.");
1939
1941
  clearInterval(intervalId);
1940
1942
  };
1941
- }, [totalCount, ...(options.dependencies ?? [])]); // This whole process triggers ONLY when totalCount changes.
1943
+ }, [totalCount, totalHeight, ...(options.dependencies ?? [])]); // This whole process triggers ONLY when totalCount changes.
1942
1944
 
1943
1945
  // Effect to handle user scrolling.
1944
1946
  useEffect(() => {
@@ -1970,6 +1972,10 @@ function createProxyHandler<T>(
1970
1972
  };
1971
1973
 
1972
1974
  const handleUserScroll = () => {
1975
+ if (isAutoScrolling.current) {
1976
+ // <--- ADD THIS CHECK
1977
+ return;
1978
+ }
1973
1979
  const isAtBottom =
1974
1980
  container.scrollHeight -
1975
1981
  container.scrollTop -