Repository navigation
Conversation
kaylendog
force-pushed
the
fix/kaylendog/flaky-timeline-at-bottom
branch
from
November 2, 2026 13:58
a46ed6b to
cf945cb
Compare
Signed-off-by: Skye Elliot <actuallyori@gmail.com>
kaylendog
force-pushed
the
fix/kaylendog/flaky-timeline-at-bottom
branch
from
November 4, 2026 12:49
84e31a8 to
38084e7
Compare
kaylendog
marked this pull request as ready for review
November 4, 2026 12:49
Member
|
Thanks for taking a look into this. I think the problem is that we are reading tanstack virtual's scroll position(that it has re-read from the DOM since the resize) with it's viewportHeight(which briefly is stale until the ResizeObserver callback fires). Feels to be like an upstream bug if two values disagree in this onChange handler. For the moment I have added a guard in in element web -> #35727. |
Member
|
In fact I've added an upstream fix for this instead(TanStack/virtual#1378) rather than work around it on the element side and created a PR bump tanstack and add it to the patch. |
Contributor
Author
|
Closing under the assumption that PR will supersede this one! Please re-open if I'm wrong. |
This branch was successfully deployed
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.
I believe the flaking test in #35449 isn't actually a flaking test, and is indicative of an actual bug with how we handle window resizes and
atBottominTimelineView.I've attempted to fix this by holding the report used in its computation for a single animation frame, which should prevent spurious flashes of the "jump-to-bottom" button, as well as fixing #35449.
See below for a full problem overview/description - I apologise for the verbosity, but it has taken me a fair old while to understand what on earth Claude has done here, and thought it best to dump my own thinking and context for those who are also uninitiated!
Fixes #35449.
Full PR overview with context (human-written!)
Context
TimelineViewtells its view model whenever the reader arrives at or leaves the bottom of the timeline, throughonAtBottomStateChange. The view model uses that flag for two things:reportVisibleStatecomputes this using three figures from the virtualiser:scrollOffset- how far the list is scrolled down;scrollRect.height- the height of the viewport; andgetTotalSize()- the summed height of every rowThese are combined into
atBottom:However, these three values are maintained by different callbacks, each of which notifies us of a change. This triggers incorrect recomputations of
atBottomwhere the three parameters above refer to different states.The test in #35449 -
keeps a reader at the bottom when the window shrinks and some rows shrink with it- does what's in the name: shrinks the window with rows sized against the viewport, such that both it and the rows change height together. TanStack watches those with two separateResizeObservers:Each of these notifies us independently when its work is done. We have a patch to
@tanstack/virtual, introduced in #35374, of which one hunk is relevant:This keeps the end in view when the scroll element resizes, which upstream only does when a row resizes. The browser preserves
scrollToprather than the distance from the bottom, so the newest message would otherwise slide under the fold when the composer grows or the window shrinks.Sequence
Breaking this down step-by-step (partly for my own sanity):
scrollRect.heightbecomes the new, smaller height.@tanstack__virtual-core@3.patchre-pins the scroll position so the bottom stays in view, adjusting byMath.min(shrink, this.getDistanceFromEnd()).applyScrollAdjustmentfolds that adjustment intoscrollOffseteagerly rather than waiting for the next scroll event, soscrollOffsetis current from here on.reportVisibleStateruns, and this is where it goes wrong.scrollRect.heightandscrollOffsetboth describe the resized layout, butgetTotalSize()still sums the pre-resize row heights - no row has been re-measured yet.scrollOffset + viewportHeightfalls short of it, andatBottomcomes outfalse.getTotalSize()drops to match the DOM.reportVisibleStateruns again. All three figures now describe the same layout, soatBottomistrue, and we report the reader arriving at a bottom they never left.In step 3, we are reading figures half way through an update, so we incorrectly flip as bottom to
falseThe user-visible effect is that dragging the window edge briefly shows the jump-to-bottom button, and a message arriving inside that window is counted as unread before the count is cleared again.Fix
Since there is no consistent set of figures to read, as per above, one solution is to hold the report for a frame.
requestAnimationFrame. If a later pass finds us at the bottom before that frame runs, it is cancelled and nothing is reported at all.Why not just read the DOM?
This is what Claude first attempted, as
v.isAtEnd(AT_BOTTOM_THRESHOLD_PX)looks like it should sidestep the problem by measuring the scroll element directly. However, It doesn't for three reasons:isAtEnd()->getDistanceFromEnd()->scrollHeight - clientHeight - scrollOffset.position: absolute(code), so they contribute nothing to the sizer's height.react-virtual'sapplyContainerSizewritescontainer.style.height = ${instance.getTotalSize()}px, and does so insideonChangeimmediately before calling ours.So
scrollHeightis not an independent measurement either, but rather the result ofgetTotalSize(). This is written to the DOM one statement earlier, carrying exactly the same staleness. The expression is arithmetically equivalent to the one it would replace.A few alternatives that Claude suggested would genuinely remove the inconsistency:
measureElement, since upstream's default deliberately refuses a synchronous read, at the cost of anoffsetHeightread per row on every measure pathBoth are more complex changes to already difficult-to-understand code, which Claude agrees should be done properly upstream, and I believe should be done by someone smarter than me.
Checklist
public/exportedsymbols have accurate TSDoc documentation.AI assistance