Repository navigation
fix(virtual-core): write a hold before a command whose target is below it #1409
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
Merged
+305
−4
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7c6d274
fix(virtual-core): write a hold before a command whose target is belo…
piecyk db995d7
fix(virtual-core): clamp a command to the element's max after writing…
piecyk 3a0826a
test: cover more commands below a held correction (#1405)
piecyk 21eac66
test: grow the row under a finger in the iOS hold spec
piecyk 9eed68c
test: run _willUpdate after a late sizer commit in the #1405 tests
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 scroll command stopping short of a target near the top while a scroll correction is held (iOS touch, or a bounce). For example, `scrollToIndex(0)` right after a tap that grew a row above the viewport ended the size of that growth below the top. The held correction is now written first, then the command. |
57 changes: 57 additions & 0 deletions
57
packages/react-virtual/e2e/app/test/ios-hold-below-target.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,57 @@ | ||
| import { expect, test } from '@playwright/test' | ||
|
|
||
| // An iPhone UA plus touch emulation puts Chromium on the iOS code path (see | ||
| // ios-programmatic-landing.spec.ts). Only the hold bookkeeping is real here, | ||
| // not WebKit's touch physics. | ||
| test.use({ | ||
| hasTouch: true, | ||
| userAgent: | ||
| 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1', | ||
| }) | ||
|
|
||
| // #1405: a row above the viewport grows during a tap (held), and the app | ||
| // jumps to the top from the tap's touchend. The target is less than the | ||
| // hold, so written the hold short it would clamp at 0 and the list would end | ||
| // the hold below the top. | ||
| for (const behavior of ['auto', 'smooth'] as const) { | ||
| test(`scrollToIndex(0) (${behavior}) after a tap reaches the top under a held correction`, async ({ | ||
| page, | ||
| browserName, | ||
| }) => { | ||
| test.skip(browserName !== 'chromium', 'touch emulation runs in Chromium') | ||
| // 50px rows, 400px viewport, at 1000: rows 15-19 are mounted above it. | ||
| await page.goto('/ios-deferral/?initialOffset=1000') | ||
| await expect | ||
| .poll(() => page.evaluate(() => (window as any).__t.el?.scrollTop)) | ||
| .toBe(1000) | ||
|
|
||
| // The row grows under a finger, which holds the correction for as long | ||
| // as it is down, so no timing matters until the lift. The tap's tail | ||
| // then lasts 150ms: the jump comes in the same task as the touchend. | ||
| const result = await page.evaluate(async (b) => { | ||
| const t = (window as any).__t | ||
| const touch = (type: string) => | ||
| t.el.dispatchEvent(new TouchEvent(type, { bubbles: true })) | ||
| touch('touchstart') | ||
| t.setH(17, 90, true) | ||
| for (let i = 0; i < 120 && t.v._holdOffset === 0; i++) { | ||
| await t.frames(1) | ||
| } | ||
| const hold = t.v._holdOffset | ||
| touch('touchend') | ||
| t.v.scrollToIndex(0, { align: 'start', behavior: b }) | ||
| for (let i = 0; i < 60 && t.el.scrollTop !== 0; i++) await t.frames(1) | ||
| await t.wait(300) | ||
| return { | ||
| hold, | ||
| top: t.el.scrollTop, | ||
| row0: t.rowTop(0), | ||
| holdAfter: t.v._holdOffset, | ||
| } | ||
| }, behavior) | ||
|
|
||
| // The correction was held when the jump was made. | ||
| expect(result.hold).toBe(40) | ||
| expect(result).toEqual({ hold: 40, top: 0, row0: 0, holdAfter: 0 }) | ||
| }) | ||
| } |
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
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.
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.