Visitar URL original
[labs/virtualizer] Re-pick the flow layout anchor when it leaves the render range by atarutin · Pull Request #5419 · lit/lit · GitHub
Skip to content

[labs/virtualizer] Re-pick the flow layout anchor when it leaves the render range - #5419

Open
atarutin wants to merge 2 commits into
lit:mainfrom
atarutin:fix/virtualizer-stale-anchor
Open

atarutin wants to merge 2 commits into
lit:mainfrom
atarutin:fix/virtualizer-stale-anchor

Conversation

@atarutin

Copy link
Copy Markdown

Fixes #5418

Bug

After a jump into unmeasured rows (for example, scrollTop = scrollHeight on a long flow-layout list), the flow layout keeps its anchor (the last item) until the layout is stable. If the user scrolls somewhere else during that window, _getItems measures the new position against the stale anchor. It computes anchorErr, adds it to _scrollError, and _correctScrollError scrolls the viewport back to the anchor. A scroll to the top made one frame after a jump to the end leaves the list at the bottom.

Fix

Re-pick the anchor when _anchorPos is outside [lower, upper]. This is the anchor-validation hunk from @graynorton's #5279, taken by itself so it can land without the rest of that stack (#5249). Only the code comment differs, because the freeze/unfreeze API that #5279's comment refers to isn't on main.

Test

src/test/scenarios/scroll-jump-anchor.test.ts jumps to the end, scrolls to 0 on the next frame, and asserts that scrollTop < 50 and that item 0 is rendered. It covers <lit-virtualizer> and virtualize() with scroller, and <lit-virtualizer> with window scrolling.

  • Without the fix, all 3 cases fail: scrollTop is 48550, 48550 and 48358. They failed the same way on 4 runs.
  • With the fix, all 3 pass. They passed on 11 runs.
  • The full virtualizer suite passes in Chrome: 85 passed and 32 skipped with CI=true, and 117 passed without it, including the skipInCI scrolling tests. tsc --target ES5, eslint and prettier are clean.

The test is a separate commit, so it can be checked out before the fix.

🤖 Generated with Claude Code

https://claude.ai/code/session_013imjkuZ1miKJ7HzHWg6Ku2

@changeset-bot

changeset-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2b8b6c1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@lit-labs/virtualizer Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

atarutin and others added 2 commits October 22, 2026 19:38
…st-jump reflow

Jump to the end of a long flow-layout list, then scroll to 0 on the
next frame. The scroll to the top is currently undone: scrollTop ends
near the bottom (~48500 in the default fixture) and item 0 is not
rendered.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013imjkuZ1miKJ7HzHWg6Ku2
Signed-off-by: Aleksandr Tarutin <atarutin@orionsbelt.net>
…render range

After a jump into unmeasured rows, the flow layout keeps its anchor
until the layout is stable. A new scroll position that lands in that
window was measured against the stale anchor; _getItems computed an
anchorErr, added it to _scrollError, and the virtualizer scrolled back
to the anchor. Choose a new anchor when the old one is outside
[lower, upper].

The change is the anchor-validation hunk from Gray Norton's lit#5279.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013imjkuZ1miKJ7HzHWg6Ku2
Signed-off-by: Aleksandr Tarutin <atarutin@orionsbelt.net>
@atarutin
atarutin force-pushed the fix/virtualizer-stale-anchor branch from 382b870 to 2b8b6c1 Compare October 22, 2026 23:39

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[labs/virtualizer] Scrolling back to the top right after a jump to the end is undone

1 participant