Reintroduce scroll restore effect for message stream
This commit is contained in:
@@ -320,6 +320,7 @@ export default function MessageStreamV2(props: MessageStreamV2Props) {
|
|||||||
const infoError = (messageInfo as { error?: { name?: string } } | undefined)?.error
|
const infoError = (messageInfo as { error?: { name?: string } } | undefined)?.error
|
||||||
const infoErrorName = typeof infoError?.name === "string" ? infoError.name : ""
|
const infoErrorName = typeof infoError?.name === "string" ? infoError.name : ""
|
||||||
const cacheSignature = [
|
const cacheSignature = [
|
||||||
|
record.id,
|
||||||
record.revision,
|
record.revision,
|
||||||
isQueued ? 1 : 0,
|
isQueued ? 1 : 0,
|
||||||
showThinking ? 1 : 0,
|
showThinking ? 1 : 0,
|
||||||
@@ -577,24 +578,41 @@ export default function MessageStreamV2(props: MessageStreamV2Props) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleScroll(event: Event) {
|
function handleScroll(event: Event) {
|
||||||
if (!containerRef) return
|
if (!containerRef) return
|
||||||
updateScrollIndicators(containerRef)
|
updateScrollIndicators(containerRef)
|
||||||
if (event.isTrusted) {
|
if (event.isTrusted) {
|
||||||
const atBottom = isNearBottom(containerRef)
|
const atBottom = isNearBottom(containerRef)
|
||||||
if (!atBottom) {
|
if (!atBottom) {
|
||||||
setAutoScroll(false)
|
setAutoScroll(false)
|
||||||
} else {
|
} else {
|
||||||
setAutoScroll(true)
|
setAutoScroll(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scheduleScrollPersist()
|
scheduleScrollPersist()
|
||||||
}
|
}
|
||||||
|
|
||||||
let previousToken: string | undefined
|
|
||||||
|
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
|
const target = containerRef
|
||||||
|
if (!target) return
|
||||||
|
scrollCache.restore(target, {
|
||||||
|
fallback: () => scrollToBottom(true),
|
||||||
|
onApplied: (snapshot) => {
|
||||||
|
if (snapshot) {
|
||||||
|
setAutoScroll(snapshot.atBottom)
|
||||||
|
} else {
|
||||||
|
const atBottom = isNearBottom(target)
|
||||||
|
setAutoScroll(atBottom)
|
||||||
|
}
|
||||||
|
updateScrollIndicators(target)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
let previousToken: string | undefined
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
|
||||||
const token = changeToken()
|
const token = changeToken()
|
||||||
if (!token || token === previousToken) {
|
if (!token || token === previousToken) {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user