-
-
Notifications
You must be signed in to change notification settings - Fork 463
fix(virtual-core): Fix #1258 #1260
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
+398
β2
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9117fc3
fix: #1258
GianlucaGuarini c294fcd
fix: E2E chat tests
GianlucaGuarini 937b7bc
fix(virtual-core): re-issue clamped end-anchor compensation once the β¦
piecyk a01c52f
fix(virtual-core): retry clamped compensation after notify so direct β¦
piecyk 4f11902
Merge branch 'main' into issue/1258
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 | ||
| --- | ||
|
|
||
| Recover the bottom pin when the browser clamps an end-anchored scroll compensation write. `resizeItem` compensates a size change by writing `scrollTop` before the consumer has committed the new total size, so when the grown item does not itself extend the scroll range the browser clamps the write to the old maximum and the viewport is left short of the end with no scroll event to correct it. Two cases hit this: `paddingEnd > 0` with a growing last item, where the overflowing item only extends `scrollHeight` to its own end and the clamp lands exactly `paddingEnd` short ([#1258](https://github.com/TanStack/virtual/issues/1258)); and a row above the last one growing while the last row keeps its size, under `directDomUpdates` ([#1266](https://github.com/TanStack/virtual/issues/1266)). A compensation write whose target exceeds the scroll maximum at write time is now recorded as clamped and re-issued once the sizer has grown β right after `notify` for consumers that size the container synchronously in `onChange`, and from `_willUpdate` for consumers that size it during a render. The clamped read-back keeps the retry pending; any other scroll event cancels it, so a user reading history is never yanked. |
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,10 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script type="module" src="./main.tsx"></script> | ||
| </body> | ||
| </html> |
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,89 @@ | ||
| // Exact reproduction of #1266, adapted from PR #1265 by @tigerBeA: an | ||
| // end-anchored direct-DOM chat where a row ABOVE the last one grows. The last | ||
| // row is exactly the viewport height and keeps its size, so its overflow cannot | ||
| // extend the scroll range before the sizer is updated, and with `useFlushSync: | ||
| // false` and an unchanged range nothing re-renders after the resize. | ||
| import React from 'react' | ||
| import { createRoot } from 'react-dom/client' | ||
| import { useVirtualizer } from '@tanstack/react-virtual' | ||
|
|
||
| const VIEWPORT_HEIGHT = 300 | ||
| const initialMessages = Array.from({ length: 8 }, (_, index) => ({ | ||
| id: `m-${index}`, | ||
| height: index === 7 ? VIEWPORT_HEIGHT : 50, | ||
| })) | ||
|
|
||
| function App() { | ||
| const [messages, setMessages] = React.useState(initialMessages) | ||
| const parentRef = React.useRef<HTMLDivElement>(null) | ||
| const virtualizer = useVirtualizer({ | ||
| count: messages.length, | ||
| getScrollElement: () => parentRef.current, | ||
| getItemKey: (index) => messages[index]!.id, | ||
| estimateSize: (index) => initialMessages[index]!.height, | ||
| anchorTo: 'end', | ||
| followOnAppend: true, | ||
| scrollEndThreshold: 4, | ||
| overscan: 4, | ||
| directDomUpdates: true, | ||
| useFlushSync: false, | ||
| }) | ||
|
|
||
| React.useLayoutEffect(() => { | ||
| virtualizer.scrollToEnd() | ||
| }, [virtualizer]) | ||
|
|
||
| return ( | ||
| <div> | ||
| <button | ||
| id="grow-previous" | ||
| onClick={() => { | ||
| setMessages((current) => | ||
| current.map((message, index) => | ||
| index === current.length - 2 | ||
| ? { ...message, height: message.height + 24 } | ||
| : message, | ||
| ), | ||
| ) | ||
| }} | ||
| > | ||
| Grow previous | ||
| </button> | ||
| <div | ||
| ref={parentRef} | ||
| id="scroll-container" | ||
| style={{ | ||
| height: VIEWPORT_HEIGHT, | ||
| width: 420, | ||
| overflow: 'auto', | ||
| overflowAnchor: 'none', | ||
| }} | ||
| > | ||
| <div | ||
| ref={virtualizer.containerRef} | ||
| style={{ position: 'relative', width: '100%' }} | ||
| > | ||
| {virtualizer.getVirtualItems().map((item) => ( | ||
| <div | ||
| key={item.key} | ||
| ref={virtualizer.measureElement} | ||
| data-index={item.index} | ||
| style={{ | ||
| position: 'absolute', | ||
| top: 0, | ||
| left: 0, | ||
| width: '100%', | ||
| }} | ||
| > | ||
| <div style={{ height: messages[item.index]!.height }}> | ||
| Message {messages[item.index]!.id} | ||
| </div> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| createRoot(document.getElementById('root')!).render(<App />) |
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
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.