mirror of https://github.com/ollama/ollama
app/ui: use requestAnimationFrame to prevent bottom line cutoff in streaming thinking display (#13137)
This commit is contained in:
parent
7cf6f18c1f
commit
c34fc64688
|
|
@ -50,21 +50,33 @@ export default function Thinking({
|
||||||
// Position content to show bottom when collapsed
|
// Position content to show bottom when collapsed
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isCollapsed && contentRef.current && wrapperRef.current) {
|
if (isCollapsed && contentRef.current && wrapperRef.current) {
|
||||||
const contentHeight = contentRef.current.scrollHeight;
|
requestAnimationFrame(() => {
|
||||||
const wrapperHeight = wrapperRef.current.clientHeight;
|
if (!contentRef.current || !wrapperRef.current) return;
|
||||||
if (contentHeight > wrapperHeight) {
|
|
||||||
const translateY = -(contentHeight - wrapperHeight);
|
const contentHeight = contentRef.current.scrollHeight;
|
||||||
contentRef.current.style.transform = `translateY(${translateY}px)`;
|
const wrapperHeight = wrapperRef.current.clientHeight;
|
||||||
setHasOverflow(true);
|
if (contentHeight > wrapperHeight) {
|
||||||
} else {
|
const translateY = -(contentHeight - wrapperHeight);
|
||||||
setHasOverflow(false);
|
contentRef.current.style.transform = `translateY(${translateY}px)`;
|
||||||
}
|
setHasOverflow(true);
|
||||||
|
} else {
|
||||||
|
contentRef.current.style.transform = "translateY(0)";
|
||||||
|
setHasOverflow(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else if (contentRef.current) {
|
} else if (contentRef.current) {
|
||||||
contentRef.current.style.transform = "translateY(0)";
|
contentRef.current.style.transform = "translateY(0)";
|
||||||
setHasOverflow(false);
|
setHasOverflow(false);
|
||||||
}
|
}
|
||||||
}, [thinking, isCollapsed]);
|
}, [thinking, isCollapsed]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (activelyThinking && wrapperRef.current && !isCollapsed) {
|
||||||
|
// When expanded and actively thinking, scroll to bottom
|
||||||
|
wrapperRef.current.scrollTop = wrapperRef.current.scrollHeight;
|
||||||
|
}
|
||||||
|
}, [thinking, activelyThinking, isCollapsed]);
|
||||||
|
|
||||||
const handleToggle = () => {
|
const handleToggle = () => {
|
||||||
setIsCollapsed(!isCollapsed);
|
setIsCollapsed(!isCollapsed);
|
||||||
setHasUserInteracted(true);
|
setHasUserInteracted(true);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue