-
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
StylesPreview: Fix endless loop of ratio calculations when on the threshold of a scrollbar #57090
StylesPreview: Fix endless loop of ratio calculations when on the threshold of a scrollbar #57090
Conversation
Size Change: +106 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
Flaky tests detected in 3ad023e. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7241395118
|
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.
Tested in Firefox, Chrome, Safari and Edge
✅ Can confirm it fixes the dancing styles preview panes. I could only reproduce on Chrome
✅ Also, the borders of the style variation previews look good on all browser in mobile view
LGTM
Thanks for going deep on this one, and removing a weird bug.
Do you think much of the workaround effort could be spared if we removed 'motion.div'? I'm not sure, but I'm assuming it's handling animations and therefore layout.
Just wondering if the old fashioned iframe.onLoad
+ frame.document.body.offsetHeight
would be simpler 🤷🏻
Thanks for the review! 🙇
Good questions! It seems some of the animations are a bit dependent on I do think this component is probably doing a little too much heavy lifting when it comes to determining ratios. Like perhaps another way of doing it would be to have a couple of hard-coded ratios that the component uses depending on a threshold size, so instead of a whole bunch of multiplication, we could just swap out one or two classes (or constants) or something? Still, it's an interesting problem when trying to get a component to perform changes reactively to the container width. I suspect there's likely one or two other components that might have this problem, too. For now, I'll leave the implementation like this (and since it's the end of the week). If there's no objections, I'll merge this one in on Monday, and happy to look into follow-ups to go for a simpler / stripped down approach! |
…eshold of a scrollbar
32a33fe
to
3ad023e
Compare
…eshold of a scrollbar (#57090) * StylesPreview: Fix endless loop of ratio calculations when on the threshold of a scrollbar * Revert stray line
What?
Similar issue to #55112
Fix the
StylesPreview
component so that it doesn't endlessly "dance" when the viewport height means that the preview's container is right at the threshold of a scrollbar appearing.Why?
As described in #55112 (comment) the ratio calculations in the
StylesPreview
component can easily wind up in an endless loop when a scrollbar is shown or hidden. It goes something like this:This issue will only be apparent at very particular viewport heights, and depending on the number of previews present. I could reproduce this issue reliably in Chrome on Mac at the following viewport heights:
568px
viewport height663px
viewport heightHow?
TL;DR — don't recalculate ratio for these previews if the change in width is only quite small (and not worth the penalty of an infinite loop)
Long story:
The fix is a little convoluted, but required a few steps to avoid an infinite loop, and keep things performant (as far as I can tell):
250ms
).0.1
— this is a big enough threshold to account for the show/hiding of the scrollbar, without having a negative effect (subjectively) on the appearance of the previewsWhile I was at it, I've also fixed an issue with the preview iframes not filling their containers in mobile viewports.
Testing Instructions
trunk
see if you can replicate the dancing previews issue by using the viewport heights from the "Why?" section above. The key screens to look at are the root of global styles in the right hand sidebar, and the style variations screen.Testing Instructions for Keyboard
Screenshots or screencast
Global styles (before — trunk)
2023-12-15.14.27.55.mp4
Style variations (before — trunk)
2023-12-15.14.27.18.mp4
Global styles (with this PR applied)
2023-12-15.14.25.30.mp4
Style variations (with this PR applied)
2023-12-15.14.26.00.mp4