fix(virtualizer): preserve subpixel precision in ScrollView to preven… - #10489
fix(virtualizer): preserve subpixel precision in ScrollView to preven…#10489devo-id wants to merge 2 commits into
Conversation
cab6ae5 to
62225e1
Compare
snowystinger
left a comment
There was a problem hiding this comment.
This seems like a better approach than the already existing PR. While the unit test is kind of useful, it'd be more useful to have a storybook setup with the 50% widths you mention, then we can put it in a chromatic story and get visual regression testing that actually uses the browser instead of mocking everything in jsdom. Would you mind putting that together?
Is there a reason you have left it as a draft?
Thank you!
…t fractional width overflow
62225e1 to
22f0f72
Compare
|
Hi @snowystinger, Thanks for taking a look and for the feedback! About the draft status: I temporarily moved it to draft while looking into a CircleCI failure in Storybook / Chromatic: I've added a I've marked the PR as ready for review. Thanks! |
What was changed
When a Virtualizer container has a fractional layout width (e.g.
250.5px, common when two components sit side-by-side in a50%flex layout), the browser's integerdom.clientWidthrounds up to251pxper the CSSOM View spec.ScrollViewwas passing this rounded integer to the layout engine, which sized the content wrapper to251pxinside a250.5pxcontainer — producing an unwanted horizontal scrollbar.Why it happened
ScrollView.tsxread container dimensions viadom.clientWidth/dom.clientHeight, which are always integers in the browser. The Virtualizer's layout engine then sized the content element to those rounded values, causing a 0.5px overflow that triggeredoverflow: autoto show a scrollbar.How it's fixed
Introduced
getClientSize(dom)inScrollView.tsxthat derives exact subpixel dimensions fromgetBoundingClientRect()while correctly subtracting borders and scrollbars (dom.offsetWidth - dom.clientWidth). This gives the layout engine the true floating-point scrollport dimensions.Fixing at the measurement source means all layouts (
ListLayout,GridLayout,WaterfallLayout, custom layouts) automatically benefit — no per-layout patching needed.✅ Pull Request Checklist:
📝 Test Instructions:
yarn jest packages/react-aria-components/test/ListBox.test.js -t "fractional container"— both tests should pass.ListBoxinside a501pxcontainer split into two50%columns (so each column is250.5px). Confirm no horizontal scrollbar appears.Closes #10471