cogsbox-state 0.5.326 → 0.5.327
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 +305 -299
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +20 -5
package/package.json
CHANGED
package/src/CogsState.tsx
CHANGED
|
@@ -1939,21 +1939,36 @@ function createProxyHandler<T>(
|
|
|
1939
1939
|
passive: true,
|
|
1940
1940
|
});
|
|
1941
1941
|
|
|
1942
|
-
|
|
1942
|
+
const hasInitiallyLoadedRef = useRef(false);
|
|
1943
|
+
const prevTotalCountRef = useRef(0);
|
|
1944
|
+
|
|
1945
|
+
// In your useLayoutEffect:
|
|
1943
1946
|
if (stickToBottom) {
|
|
1944
|
-
//
|
|
1945
|
-
|
|
1947
|
+
// Check if this is initial load or new item
|
|
1948
|
+
const isInitialLoad =
|
|
1949
|
+
!hasInitiallyLoadedRef.current && totalCount > 0;
|
|
1950
|
+
const isNewItem =
|
|
1951
|
+
hasInitiallyLoadedRef.current &&
|
|
1952
|
+
totalCount > prevTotalCountRef.current;
|
|
1953
|
+
|
|
1946
1954
|
scrollTimeoutId = setTimeout(() => {
|
|
1947
1955
|
console.log("totalHeight", totalHeight);
|
|
1948
1956
|
if (isLockedToBottomRef.current) {
|
|
1949
1957
|
container.scrollTo({
|
|
1950
1958
|
top: 999999999,
|
|
1951
|
-
behavior: "auto", //
|
|
1959
|
+
behavior: isNewItem ? "smooth" : "auto", // Only smooth for NEW items after initial load
|
|
1952
1960
|
});
|
|
1953
1961
|
}
|
|
1954
|
-
},
|
|
1962
|
+
}, 200);
|
|
1963
|
+
|
|
1964
|
+
// Mark as initially loaded after first run
|
|
1965
|
+
if (isInitialLoad) {
|
|
1966
|
+
hasInitiallyLoadedRef.current = true;
|
|
1967
|
+
}
|
|
1955
1968
|
}
|
|
1956
1969
|
|
|
1970
|
+
// Update ref at the end
|
|
1971
|
+
prevTotalCountRef.current = totalCount;
|
|
1957
1972
|
updateVirtualRange();
|
|
1958
1973
|
|
|
1959
1974
|
// Cleanup function is vital to prevent memory leaks.
|