Skip to content

Commit aece29f

Browse files
committed
fix(app): prevent scroll jump during history backfill
Use relative scroll adjustment (scrollTop += delta) instead of restoring a captured absolute position (scrollTop = beforeTop + delta). The previous approach captured scrollTop before the DOM update and restored it inside requestAnimationFrame. During fast scrolling, native scroll events fire between capture and the rAF callback, making the captured value stale and causing the viewport to jump. Keep rAF so async rendering (markdown parsing, syntax highlighting) can settle before measuring the final scrollHeight. The relative adjustment reads scrollTop at rAF time, so it stays fresh regardless of user scrolling in the interim. Fixes anomalyco#17996
1 parent d5337b4 commit aece29f

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

‎packages/app/src/pages/session.tsx‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,11 @@ function createSessionHistoryWindow(input: SessionHistoryWindowInput) {
132132
fn()
133133
return
134134
}
135-
const beforeTop = el.scrollTop
136-
const beforeHeight = el.scrollHeight
135+
const height = el.scrollHeight
137136
fn()
138137
requestAnimationFrame(() => {
139-
const delta = el.scrollHeight - beforeHeight
140-
if (!delta) return
141-
el.scrollTop = beforeTop + delta
138+
const delta = el.scrollHeight - height
139+
if (delta) el.scrollTop += delta
142140
})
143141
}
144142

0 commit comments

Comments
 (0)