Repository navigation
fix(virtual-core): land a smooth command aimed before a wheel hold #1408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
piecyk
wants to merge
8
commits into
TanStack:main
Choose a base branch
from
piecyk:fix/smooth-command-wheel-hold
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+487
−11
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cbc2d66
fix(virtual-core): land a smooth command aimed before a wheel hold
piecyk 80015b6
fix(virtual-core): don't rewrite a command replaced during the hold's…
piecyk 2fb9100
fix(virtual-core): don't write the hold over a command started in its…
piecyk 281a58f
fix(virtual-core): re-aim any smooth command when the wheel hold ends
piecyk 9550796
fix(virtual-core): clamp a command written again to the element's cur…
piecyk cef9ee2
test: cover the wheel hold behind a smooth command in WebKit
piecyk 6d142e6
fix(virtual-core): clamp a command written again to 0 as well
piecyk fa96d8b
test: start the WebKit wheel spec's command inside the wheel event
piecyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/virtual-core': patch | ||
| --- | ||
|
|
||
| Fix a smooth `scrollToIndex` or `scrollToOffset` in WebKit stopping short of its target when rows are prepended or measured during wheel input while it travels. The held correction is now written when the wheel rests, and the scroll continues to its target. |
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
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
76 changes: 76 additions & 0 deletions
76
packages/react-virtual/e2e/app/test/wheel-smooth-prepend.spec.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { expect, test } from '@playwright/test' | ||
| import type { Page } from '@playwright/test' | ||
|
|
||
| // The wheel hold is WebKit only (#1400), so this runs in WebKit. | ||
| test.use({ browserName: 'webkit' }) | ||
|
|
||
| const scrollTop = (page: Page) => | ||
| page.evaluate(() => document.querySelector('#scroll-container')!.scrollTop) | ||
|
|
||
| // Where row 0 is drawn, relative to the top of the viewport. | ||
| const rowZeroTop = (page: Page) => | ||
| page.evaluate(() => { | ||
| const container = document.querySelector('#scroll-container')! | ||
| const row = container.querySelector('[data-index="0"]') | ||
| if (!row) return null | ||
| return ( | ||
| row.getBoundingClientRect().top - | ||
| container.getBoundingClientRect().top - | ||
| container.clientTop | ||
| ) | ||
| }) | ||
|
|
||
| // #1406: a smooth scrollToIndex(0) travels, a wheel event comes in, and rows | ||
| // are prepended within the wheel's 150ms, so the anchor is held. A real wheel | ||
| // does not stop the smooth animation in WebKit, so the element reaches 0 | ||
| // while the layout is the held 250px away. The command must still land on | ||
| // the new row 0, with the hold written. | ||
| test('a prepend held under the wheel does not strand a smooth scrollToIndex', async ({ | ||
| page, | ||
| }) => { | ||
| await page.goto('/smooth-prepend/') | ||
| await expect | ||
| .poll(() => | ||
| page.evaluate(() => { | ||
| const c = document.querySelector('#scroll-container')! | ||
| return Math.abs(c.scrollHeight - c.scrollTop - c.clientHeight) | ||
| }), | ||
| ) | ||
| .toBeLessThan(1.01) | ||
|
|
||
| // All of it inside one real wheel event, so no round trip has to fit into | ||
| // WebKit's ~250ms animation: a capture listener on the window starts the | ||
| // smooth command before the virtualizer's own wheel listener opens the | ||
| // wheel window, and a listener after it prepends, which is then held. The | ||
| // wheel's own scroll lands while the command travels. | ||
| await page.evaluate(() => { | ||
| const container = document.querySelector('#scroll-container')! | ||
| window.addEventListener( | ||
| 'wheel', | ||
| () => document.querySelector<HTMLButtonElement>('#smooth-to-0')!.click(), | ||
| { capture: true, once: true }, | ||
| ) | ||
| container.addEventListener( | ||
| 'wheel', | ||
| () => { | ||
| ;(window as any).prependedAt = container.scrollTop | ||
| document.querySelector<HTMLButtonElement>('#prepend')!.click() | ||
| }, | ||
| { once: true }, | ||
| ) | ||
| }) | ||
| const box = (await page.locator('#scroll-container').boundingBox())! | ||
| await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2) | ||
| await page.mouse.wheel(0, -40) | ||
|
|
||
| // The prepend came while the command was still travelling, not after it. | ||
| const prependedAt = await page.evaluate(() => (window as any).prependedAt) | ||
| expect(prependedAt).toBeGreaterThan(500) | ||
|
|
||
| await expect.poll(() => rowZeroTop(page), { timeout: 3000 }).toBe(0) | ||
| expect(await scrollTop(page)).toBeLessThan(1.01) | ||
| await expect(page.locator('[data-index="0"]')).toHaveAttribute( | ||
| 'data-message-id', | ||
| 'm--5', | ||
| ) | ||
| }) |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.