-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix auto-size patterns triggering scrollbar flickering on certain size #52921
Conversation
// Those inline styles are calculated to fit a perfect thumbnail. | ||
width: 100%; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this breaks other usages of this component elsewhere. I've tested it both in the patterns screen and in the inserter, but there might be more edge cases?
@t-hamano Could you be kind enough to help me test this on Windows? 🙇 Since you're the original reporter and you use Windows. Thanks! |
Size Change: +523 B (0%) Total Size: 1.44 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for tackling a complicated problem 😅 I have only one comment regarding the error log, but it seems to be working as expected on Windows.
b470a972a16207cd06e1bbcb189c99b5.mp4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests well for me with @t-hamano's suggested tweak to prevent the Infinity
aspect ratio value.
I couldn't spot any issues across browsers, Mac or Windows (only VM I have setup). The previews in the inserter and pattern lists (e.g. query block) all look the same before and after this PR.
Nice work @kevin940726 👍
Flaky tests detected in 83a806e. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5662986379
|
Let's try this. If something breaks, someone will yell at this 😆 . |
What?
Fix #52027. Prevents
BlockPreview
s from flickering on certain viewport sizes.Why?
The issue happens when the scrollbar has a width and causes the viewport width to decrease when there's scrollable content.
<BlockPreview>
component uses dynamicheight
to auto-resize itself based on the preview content's height and container's width. The formula for calculating the height isheight = contentHeight * (containerWidth / viewportWidth)
whereviewportWidth
is often a constant integer andcontentHeight
also doesn't change for each pattern.containerWidth
to decrease a little bit.containerWidth
gets smaller, based on the formula in (1.), the height also gets smaller.<BlockPreview>
gets smaller in height, the scrollable content can now fit in the screen and doesn't require a scrollbar.containerWidth
now also grows bigger.containerWidth
is now bigger, based on the formula in (1.), theheight
also grows bigger. The grown amount causes the content to overflow, and the scrollbar appears again.How?
The solution might not be obvious, but excluding the scrollbar width right before the content overflows magically solves the issue. The key is that if the delta of height isn't enough to cause the transition of the width change, then it won't cause the flickering. I believe it can be proved with some math but I'd rather not go into that rabbit hole 😅.
Surprisingly, browsers natively handle this for us. The only gotcha is that we have to define
width
instead ofheight
for some reason. Hence the solution in this PR is simply to usewidth: 100%
andaspect-ratio
to mimic the same behavior with dynamic height. It's also possibly more performant as we only change compositor-only properties.I've only tested this on macOS though, I'm not sure if other OSes behave differently. Could someone with access to Windows or Linux help test this?
Testing Instructions
Testing Instructions for Keyboard
Repeat the same above but use keyboard to resize the window (I don't know how to do that?).
Screenshots or screencast
Before
Kapture.2023-07-25.at.14.26.20.mp4
After
52027-after.mp4