fix (react-dialog): Use consistent rounding for clientHeight and innerHeight#32480
Merged
emmayjiang merged 2 commits intomicrosoft:masterfrom Sep 10, 2024
Merged
Conversation
khmakoto
approved these changes
Sep 6, 2024
micahgodbolt
approved these changes
Sep 6, 2024
bsunderhus
reviewed
Sep 10, 2024
packages/react-components/react-dialog/library/src/utils/useDisableBodyScroll.ts
Show resolved
Hide resolved
bsunderhus
approved these changes
Sep 10, 2024
Contributor
bsunderhus
left a comment
There was a problem hiding this comment.
LGTM ✅ I'm not a big fan of the extra style recalc that this introduces but I believe it is unavoidable if we want to fix #32481
Thanks for the PR @CampbellOwen 💪🏻
marcosmoura
added a commit
to marcosmoura/fluentui
that referenced
this pull request
Sep 12, 2024
* master: (77 commits) fix(react-drawer): update scroll state when children changes (microsoft#32818) feat(react-storybook-addon): improve addon to more readable names (microsoft#32815) chore: cleanup react-carousel-preview (microsoft#32475) feat(storybook): add rtl/ltr toggle storybook addon (microsoft#32814) Carousel: Storybook updates and fixing exports/focus (microsoft#32457) release: applying package updates - react v8 release: applying package updates - web-components Update d3 dependency versions to 3.x.x and 4.x.x (microsoft#32463) RFC: Extended Design Tokens for Fluent UI React (microsoft#32058) update doc to reflect setTheme function change (microsoft#32490) fix (react-dialog): Use consistent rounding for clientHeight and innerHeight (microsoft#32480) fix(public-doscite-v9): global styles should not be applied to story elements (microsoft#32472) feat(workspace-plugin): implement verify-packaging executor (microsoft#32403) release: applying package updates - react-components Add strokeDasharray property when optimizeLargeData is true (microsoft#32494) fix(TreeItemLayout): Actions should not unmount between successive mouse events (microsoft#32477) release: applying package updates - react v8 bugfix(react-tree): recover from tabIndex=-1 when TreeItem is removed (microsoft#32442) Fix onResolveSuggestions not being called after component is remounted in react 18 strict mode (microsoft#28227) fix(codeowners): update most packages owned by cxe-red with cxe-prg (microsoft#32445) ...
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Previous Behavior
When calculating whether scrollbars are present, we compare the body's clientHeight to the window's innerHeight.
In the case when this height is a fractional value,
clientHeightrounds to the nearest integer whereasinnerHeightalways rounds down. This means when the body is set to 100% height and the browser is at a fractional height (usually due to a non-100% zoom factor), clientHeight often reports being 1 pixel taller than innerHeight.This causes the
scrollbar-gutter: stablestyle to be added, which reserves space for the non-existent scrollbar, shifting the layout.Repro:
https://stackblitz.com/edit/u47vqq?file=index.html
New Behavior
Match
innerHeight's rounding behaviour by usingbody.getBoundingClientRect().heightand manually rounding down.According to mdn,
getBoundingClientRect()is the equivalent toclientHeightexcept it returns the real fractional value: https://developer.mozilla.org/en-US/docs/Web/API/Element/clientHeightFixes #32481