Repository navigation
fix(virtual-core): measure the visible scroll viewport #1326
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/virtual-core': patch | ||
| --- | ||
|
|
||
| Measure the scroll viewport using client dimensions so borders and scrollbars do not obscure end-aligned items. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,8 +74,8 @@ export interface Rect { | |
| // | ||
|
|
||
| const getRect = (element: HTMLElement): Rect => { | ||
| const { offsetWidth, offsetHeight } = element | ||
| return { width: offsetWidth, height: offsetHeight } | ||
| const { clientWidth, clientHeight } = element | ||
| return { width: clientWidth, height: clientHeight } | ||
| } | ||
|
|
||
| // Animation frames for `useAnimationFrameWithResizeObserver`, requested from | ||
|
|
@@ -141,16 +141,8 @@ export const observeElementRect = <T extends Element>( | |
| } | ||
|
|
||
| const frames = createFrameQueue(targetWindow) | ||
| const observer = new targetWindow.ResizeObserver((entries) => { | ||
| const observer = new targetWindow.ResizeObserver(() => { | ||
| const run = () => { | ||
| const entry = entries[0] | ||
| if (entry?.borderBoxSize) { | ||
| const box = entry.borderBoxSize[0] | ||
| if (box) { | ||
| handler({ width: box.inlineSize, height: box.blockSize }) | ||
| return | ||
| } | ||
| } | ||
| handler(getRect(element as unknown as HTMLElement)) | ||
| } | ||
|
|
||
|
|
@@ -159,7 +151,7 @@ export const observeElementRect = <T extends Element>( | |
| : run() | ||
| }) | ||
|
|
||
| observer.observe(element, { box: 'border-box' }) | ||
| observer.observe(element, { box: 'content-box' }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Also observe changes to the viewport padding. If a scroll element has a fixed content-box width and its padding decreases, 🤖 Prompt for AI Agents
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Padding-only changes on a content-box-sized scroll container are rare, and the scrollbar toggle is the common case, which is covered. I’m fine keeping one observer here; we can add a second border-box observer in a follow-up if someone hits it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @piecyk Thanks for the guidance. Keeping one Would you like a follow-up issue, or leave it deferred without one? ✏️ Learnings added
You are interacting with an AI system. |
||
|
|
||
| return () => { | ||
| observer.unobserve(element) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.