cogsbox-state 0.5.326 → 0.5.328
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/dist/CogsState.jsx +543 -539
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +19 -5
package/package.json
CHANGED
package/src/CogsState.tsx
CHANGED
|
@@ -1819,6 +1819,8 @@ function createProxyHandler<T>(
|
|
|
1819
1819
|
|
|
1820
1820
|
// This state triggers a re-render when item heights change.
|
|
1821
1821
|
const [shadowUpdateTrigger, setShadowUpdateTrigger] = useState(0);
|
|
1822
|
+
const hasInitiallyLoadedRef = useRef(false);
|
|
1823
|
+
const prevTotalCountRef = useRef(0);
|
|
1822
1824
|
|
|
1823
1825
|
useEffect(() => {
|
|
1824
1826
|
const unsubscribe = getGlobalStore
|
|
@@ -1939,21 +1941,33 @@ function createProxyHandler<T>(
|
|
|
1939
1941
|
passive: true,
|
|
1940
1942
|
});
|
|
1941
1943
|
|
|
1942
|
-
//
|
|
1944
|
+
// In your useLayoutEffect:
|
|
1943
1945
|
if (stickToBottom) {
|
|
1944
|
-
//
|
|
1945
|
-
|
|
1946
|
+
// Check if this is initial load or new item
|
|
1947
|
+
const isInitialLoad =
|
|
1948
|
+
!hasInitiallyLoadedRef.current && totalCount > 0;
|
|
1949
|
+
const isNewItem =
|
|
1950
|
+
hasInitiallyLoadedRef.current &&
|
|
1951
|
+
totalCount > prevTotalCountRef.current;
|
|
1952
|
+
|
|
1946
1953
|
scrollTimeoutId = setTimeout(() => {
|
|
1947
1954
|
console.log("totalHeight", totalHeight);
|
|
1948
1955
|
if (isLockedToBottomRef.current) {
|
|
1949
1956
|
container.scrollTo({
|
|
1950
1957
|
top: 999999999,
|
|
1951
|
-
behavior: "auto", //
|
|
1958
|
+
behavior: isNewItem ? "smooth" : "auto", // Only smooth for NEW items after initial load
|
|
1952
1959
|
});
|
|
1953
1960
|
}
|
|
1954
|
-
},
|
|
1961
|
+
}, 200);
|
|
1962
|
+
|
|
1963
|
+
// Mark as initially loaded after first run
|
|
1964
|
+
if (isInitialLoad) {
|
|
1965
|
+
hasInitiallyLoadedRef.current = true;
|
|
1966
|
+
}
|
|
1955
1967
|
}
|
|
1956
1968
|
|
|
1969
|
+
// Update ref at the end
|
|
1970
|
+
prevTotalCountRef.current = totalCount;
|
|
1957
1971
|
updateVirtualRange();
|
|
1958
1972
|
|
|
1959
1973
|
// Cleanup function is vital to prevent memory leaks.
|