cogsbox-state 0.5.330 → 0.5.332
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 +468 -472
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +15 -20
package/package.json
CHANGED
package/src/CogsState.tsx
CHANGED
|
@@ -1816,7 +1816,7 @@ function createProxyHandler<T>(
|
|
|
1816
1816
|
|
|
1817
1817
|
// This ref tracks if the user is locked to the bottom.
|
|
1818
1818
|
const isLockedToBottomRef = useRef(stickToBottom);
|
|
1819
|
-
|
|
1819
|
+
|
|
1820
1820
|
// This state triggers a re-render when item heights change.
|
|
1821
1821
|
const [shadowUpdateTrigger, setShadowUpdateTrigger] = useState(0);
|
|
1822
1822
|
|
|
@@ -1939,31 +1939,26 @@ function createProxyHandler<T>(
|
|
|
1939
1939
|
passive: true,
|
|
1940
1940
|
});
|
|
1941
1941
|
|
|
1942
|
+
// --- THE CORE FIX ---
|
|
1942
1943
|
if (stickToBottom && isLockedToBottomRef.current) {
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
container.scrollTo({
|
|
1956
|
-
top: 999999999,
|
|
1957
|
-
behavior: isLargeGap ? "auto" : "smooth", // Instant for big jumps, smooth for small
|
|
1958
|
-
});
|
|
1959
|
-
|
|
1960
|
-
lastScrollPositionRef.current = currentScrollHeight;
|
|
1961
|
-
}
|
|
1944
|
+
// We use a timeout to wait for React to render AND for useMeasure to update heights.
|
|
1945
|
+
// This is the CRUCIAL part that fixes the race condition.
|
|
1946
|
+
scrollTimeoutId = setTimeout(() => {
|
|
1947
|
+
console.log("totalHeight", totalHeight);
|
|
1948
|
+
if (isLockedToBottomRef.current) {
|
|
1949
|
+
container.scrollTo({
|
|
1950
|
+
top: 999999999,
|
|
1951
|
+
behavior: "smooth", // ALWAYS 'auto' for an instant, correct jump.
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
}, 200); // A small 50ms delay is a robust buffer.
|
|
1962
1955
|
}
|
|
1956
|
+
|
|
1963
1957
|
updateVirtualRange();
|
|
1964
1958
|
|
|
1965
1959
|
// Cleanup function is vital to prevent memory leaks.
|
|
1966
1960
|
return () => {
|
|
1961
|
+
clearTimeout(scrollTimeoutId);
|
|
1967
1962
|
container.removeEventListener("scroll", handleUserScroll);
|
|
1968
1963
|
};
|
|
1969
1964
|
// This effect re-runs whenever the list size or item heights change.
|