From 7e7a974e774395ee326cba7de3eb2416dc043faa Mon Sep 17 00:00:00 2001 From: Max schwenk Date: Sun, 20 Sep 2026 13:46:51 -0400 Subject: [PATCH 1/3] fix(app): recover timeline offset after silent scroll reset --- .../app/src/session/timeline/virtualizer.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/app/src/session/timeline/virtualizer.tsx b/packages/app/src/session/timeline/virtualizer.tsx index 76b98e2fa675..6433075d91c0 100644 --- a/packages/app/src/session/timeline/virtualizer.tsx +++ b/packages/app/src/session/timeline/virtualizer.tsx @@ -419,6 +419,25 @@ export function createTimelineVirtualizer(input: Input) { input.onHistoryScroll() } + let offsetCheck: number | undefined + onMount(() => { + // A remounted scroll view can reset scrollTop without dispatching scroll. Keep + // TanStack's range in sync so its previously virtualized rows do not leave a gap. + offsetCheck = window.setInterval(() => { + const root = listRoot() + if (!root?.isConnected || !reportOffset) return + const observed = virtualizer.scrollOffset ?? 0 + if (Math.abs(root.scrollTop - observed) <= 1) return + if (pointerHeld && root.scrollTop < observed) input.onUnpin() + reportOffset(root.scrollTop, false) + if (input.pinned()) virtualizer.scrollToEnd() + input.onScheduleScrollState(root) + }, 200) + }) + onCleanup(() => { + if (offsetCheck !== undefined) window.clearInterval(offsetCheck) + }) + function View(props: ViewProps) { function VirtualRow(rowProps: { rowKey: string }) { let element: HTMLDivElement From c5935d15df767cef8a56bd5fda7596e4fab1fc47 Mon Sep 17 00:00:00 2001 From: Max schwenk Date: Sun, 20 Sep 2026 13:57:08 -0400 Subject: [PATCH 2/3] fix(app): preserve position across silent timeline reset --- .../app/src/session/timeline/virtualizer.tsx | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/app/src/session/timeline/virtualizer.tsx b/packages/app/src/session/timeline/virtualizer.tsx index 6433075d91c0..6206c0be90bd 100644 --- a/packages/app/src/session/timeline/virtualizer.tsx +++ b/packages/app/src/session/timeline/virtualizer.tsx @@ -134,6 +134,7 @@ export function createTimelineVirtualizer(input: Input) { const measuredElements = new WeakSet() let touchStart: number | undefined let pointerHeld = false + let upwardIntent = false let maxScroll = 0 let virtualContent: HTMLDivElement | undefined let scrollTop = 0 @@ -357,7 +358,10 @@ export function createTimelineVirtualizer(input: Input) { // the end must stop following, even though the resulting position still looks like the end. const handleListWheel = (event: WheelEvent & { currentTarget: HTMLDivElement }) => { input.onUserScroll(event.target) - if (event.deltaY < 0) input.onUnpin() + if (event.deltaY < 0) { + upwardIntent = true + input.onUnpin() + } } const handleListTouchStart = (event: TouchEvent) => { @@ -371,6 +375,7 @@ export function createTimelineVirtualizer(input: Input) { // Dragging the content downward reveals earlier messages. if (current <= touchStart) return touchStart = current + upwardIntent = true input.onUnpin() } @@ -398,7 +403,10 @@ export function createTimelineVirtualizer(input: Input) { if (!isScrollKeyTarget(event.target, key)) return if (scrollKeyOwner(event.currentTarget, event.target, key) !== event.currentTarget) return input.onUserScroll(event.currentTarget) - if (upwardKeys.has(key)) input.onUnpin() + if (upwardKeys.has(key)) { + upwardIntent = true + input.onUnpin() + } } // Following resumes by arriving at the end, either by scrolling there or by content shrinking @@ -414,6 +422,7 @@ export function createTimelineVirtualizer(input: Input) { const arrived = scrollTop > previousTop + endEpsilon || maxScroll < previousMaxScroll if (maxScroll <= 1 || (atEnd && arrived)) input.onPin() else if (pointerHeld && scrollTop < previousTop - endEpsilon) input.onUnpin() + upwardIntent = false settleColdBottom() input.onScheduleScrollState(root) input.onHistoryScroll() @@ -421,18 +430,26 @@ export function createTimelineVirtualizer(input: Input) { let offsetCheck: number | undefined onMount(() => { - // A remounted scroll view can reset scrollTop without dispatching scroll. Keep - // TanStack's range in sync so its previously virtualized rows do not leave a gap. + // A remounted scroll view can reset scrollTop without dispatching scroll. Restore + // the last observed position before TanStack paints rows for the wrong offset. offsetCheck = window.setInterval(() => { const root = listRoot() if (!root?.isConnected || !reportOffset) return const observed = virtualizer.scrollOffset ?? 0 if (Math.abs(root.scrollTop - observed) <= 1) return if (pointerHeld && root.scrollTop < observed) input.onUnpin() + if (!pointerHeld && !upwardIntent && root.scrollTop < observed - 1 && scrollTop > 1) { + const end = root.scrollHeight - root.clientHeight + const target = maxScroll - scrollTop <= endEpsilon ? end : Math.min(scrollTop, end) + if (target > root.scrollTop + 1) root.scrollTop = target + } reportOffset(root.scrollTop, false) if (input.pinned()) virtualizer.scrollToEnd() + scrollTop = root.scrollTop + maxScroll = root.scrollHeight - root.clientHeight input.onScheduleScrollState(root) - }, 200) + input.onHistoryScroll() + }, 100) }) onCleanup(() => { if (offsetCheck !== undefined) window.clearInterval(offsetCheck) From db05bf5105b768054507182b7473d4e777de80bb Mon Sep 17 00:00:00 2001 From: Max schwenk Date: Sun, 20 Sep 2026 14:18:14 -0400 Subject: [PATCH 3/3] fix(app): restore timeline binding after document adoption --- .../app/src/session/timeline/virtualizer.tsx | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/packages/app/src/session/timeline/virtualizer.tsx b/packages/app/src/session/timeline/virtualizer.tsx index 6206c0be90bd..40b2bc760c28 100644 --- a/packages/app/src/session/timeline/virtualizer.tsx +++ b/packages/app/src/session/timeline/virtualizer.tsx @@ -344,14 +344,33 @@ export function createTimelineVirtualizer(input: Input) { const bindListRoot = (root: HTMLDivElement) => { if (root === listRoot()) return - // TanStack owns anchoring; browser scroll anchoring would fight its adjustments. - root.style.overflowAnchor = "none" - setListRoot(root) - scrollTop = root.scrollTop - maxScroll = root.scrollHeight - root.clientHeight - input.setScrollRef(root) - viewportObserver?.observe(root) - settleColdBottom() + let adoptionObserver: ResizeObserver | undefined + let active = true + const bind = () => { + // Solid can mount inside an inert template document. TanStack captures its + // window on attachment and cannot install observers until the node is adopted. + if (!active || root === listRoot() || !root.ownerDocument.defaultView) return + adoptionObserver?.disconnect() + // TanStack owns anchoring; browser scroll anchoring would fight its adjustments. + root.style.overflowAnchor = "none" + setListRoot(root) + scrollTop = root.scrollTop + maxScroll = root.scrollHeight - root.clientHeight + input.setScrollRef(root) + viewportObserver?.observe(root) + settleColdBottom() + } + if (root.ownerDocument.defaultView) { + bind() + return + } + adoptionObserver = new ResizeObserver(bind) + adoptionObserver.observe(root) + onCleanup(() => { + active = false + adoptionObserver?.disconnect() + }) + queueMicrotask(bind) } // Upward input is the one intent geometry cannot recover: nudging up while still a pixel from