fix: hold the scroll position when older events load above - #4007
Merged
Merged
Conversation
Contributor
Author
Reproduced on staging, and the fix measured at zero driftAttached Playwright to a real Chrome over CDP against As deployedTimeline:
With
|
`#logs-list` is `column-reverse`, so the top button inserts older events at the visual top and pushes every row below them down. Two things moved the scroll on that load and neither knew about the other. `updated/0` ran `restoreScrollAnchor/0` to hold the visible row in place, while `put_event_page/3` pushed `scroll-to-event` to jump the oldest new row to the top. Both ran inside `requestAnimationFrame`, so the later one won, and a following diff ran the anchor restore again. Both errors scale with the height of the batch, so a wrapped log line made the jump obvious. - Drop `push_scroll_to_oldest/2` and the `scroll-to-event` push. Nothing else used that event, so the hook handler goes too. The anchor restore is now the only owner of the scroll on a page load. - Stop falling back to `window.scrollTo(0, this.scrollPosition)`. That offset is stale once rows land above the viewport, and it was wrong by exactly the height of those rows. Leave the scroll alone instead. - Keep an anchor only when the row carries an id. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
chasers
force-pushed
the
fix/load-more-top-scroll-anchor
branch
from
September 18, 2026 18:05
0d7566b to
6426ee5
Compare
The unit tests around this fix stub `getBoundingClientRect`, so they pass whatever the real layout does. `#logs-list` is `column-reverse`, and only a browser works out where a row lands once older rows enter above it. The test reads a visible row's viewport position, loads an older page, and asserts the row did not move. Messages carry a long stack-trace tail so rows wrap, which is the case that makes the drift large. I could not run it locally. The whole feature suite fails on this machine, including `searches logs from the search page`, which predates this work and renders no rows. `E2E=true` and `npm run deploy --prefix assets` did not change that. The e2e workflow watches `test/e2e/features/**`, so the PR run exercises it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011XYNBQPEPUvDU2ESE4Gcaa
amokan
requested changes
Sep 18, 2026
- Restore the anchor inline in `updated/0` rather than on the next frame.
`beforeUpdate` captures synchronously, so a following diff could capture
an already shifted top and cancel the first correction. The DOM is
patched by the time `updated/0` runs, and `getBoundingClientRect` forces
layout, so the inline read is correct.
- Cover that ordering: the anchor moves before any frame runs.
- Drop the `requestAnimationFrame` stub the anchor tests no longer need.
- Drop `refute_push_event(view, "scroll-to-event", %{})`. No code path
emits that event now, and the e2e test covers the behaviour it stood in
for.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011XYNBQPEPUvDU2ESE4Gcaa
Reinstates `refute_push_event(view, "scroll-to-event", %{})` on the
previous-page test.
The review asked to drop it as unfailable. It is not: it fails the moment
`push_scroll_to_oldest/2` comes back, which is the regression this branch
exists to prevent. The e2e test covers the same ground through the
browser, but it is one feature test away from leaving this branch with no
cheap guard at all.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011XYNBQPEPUvDU2ESE4Gcaa
amokan
approved these changes
Sep 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows #3986. Reported on staging: clicking "Load more" at the top moves the viewport, and the jump is obvious when a log line wraps to several lines.
Cause
#logs-listisflex-direction: column-reverse, so the top button inserts older events at the visual top and pushes every row below them down.Two things moved the scroll on that load, and neither knew about the other:
updated/0ranrestoreScrollAnchor/0, holding the visible row in place.put_event_page/3pushedscroll-to-event, jumping the oldest new row to the top.Both ran inside
requestAnimationFrame, so whichever fired second won. A following diff (the URL patch, the chart, the buttons) ran the anchor restore again.updated/0guarded the restore forscroll-to-bottomonly, soscroll-to-eventnever got that discipline.Both failure modes scale with the height of the inserted batch, which is why wrapped lines made it visible and single lines did not.
Fix
push_scroll_to_oldest/2and thescroll-to-eventpush. Nothing else used that event, so the hook handler goes too. The anchor restore is now the only owner of the scroll on a page load.window.scrollTo(0, this.scrollPosition). That offset is stale once rows land above the viewport, and it was wrong by exactly the height of those rows.Tests
The "anchor row is gone" test fails against the old fallback and passes against the fix. I verified both directions.
format,lint.all,test.slop(27/29) andtest.structurepassPlease confirm on staging with a source that has wrapped log lines.
🤖 Generated with Claude Code