Skip to content
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

Site Editor: style variation preview visually jumps at certain browser height #55112

Closed
lukecarbis opened this issue Oct 5, 2023 · 5 comments · Fixed by #55183
Closed

Site Editor: style variation preview visually jumps at certain browser height #55112

lukecarbis opened this issue Oct 5, 2023 · 5 comments · Fixed by #55183
Assignees
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@lukecarbis
Copy link
Contributor

Description

When viewing the styles panel with just the right browser height (something close to 1000px for me – which incidentally is the full height on a 2023 MacBook Pro with the dock hidden), the previews jump and move around the screen constantly.

This seems to occur because the scroll bar on MacOS only shows when there's content to scroll. The Previews seem like the try to scale up to fit the available space. When they do, they cause the scroll bar to display, which reduces the available space. The previews then shrink again, causing the scroll bar to hide. This loops indefinitely.

Changing the System Setting > Appearance > Show scroll bars to "Always" prevents the problem from occurring.

Step-by-step reproduction instructions

  1. On MacOS, set the System Setting > Appearance > Show scroll bars setting to "When scrolling"
  2. Open your WordPress site in Safari
  3. Navigate to Appearance > Editor > Styles
  4. Resize your browser window to be around 1000px high – just on the edge of whether the scrollbar should display (I've found there's a range of around 20px or so where this bug is triggered)

Screenshots, screen recording, code snippet

2023-10-06 07 49 32

Screen.Recording.2023-10-06.at.8.18.39.am.mov
Screenshot 2023-10-06 at 8 24 52 am

Environment info

  • WordPress 6.3.1
  • With and without Gutenberg 16.7.0 enabled
  • Safari 17.0
  • Desktop with MacOS Sonoma
  • Twenty Twenty-Three

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@lukecarbis lukecarbis added the [Type] Bug An existing feature does not function as intended label Oct 5, 2023
@annezazu annezazu added the [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") label Oct 6, 2023
@annezazu annezazu changed the title Infinite Style preview "jumps" in the left hand styles panel Site Editor: style variation preview visually jumps at certain browser height Oct 6, 2023
@annezazu
Copy link
Contributor

annezazu commented Oct 6, 2023

Tentatively adding to 6.4's board since it's occurring with 16.7 and could be present in the release. I can't replicate in Chrome nor in Safari on MacOS Ventura 13.6 using 6.3.1 and GB 16.7. I had system settings set to the following:

Screenshot 2023-10-06 at 8 57 48 AM

But couldn't replicate across any of the options. Going to add needs testing label for now as I can't replicate.

@annezazu annezazu added the Needs Testing Needs further testing to be confirmed. label Oct 6, 2023
@ironprogrammer
Copy link
Contributor

ironprogrammer commented Oct 6, 2023

Thanks for the report, @lukecarbis! I was also able to reproduce this one.

Test Report

Environment

  • Hardware: MacBook Pro Apple M1 Pro
  • OS: macOS 13.6
  • Browser: Safari 16.6
  • Server: nginx/1.25.2
  • PHP: 7.4.33
  • WordPress: 6.4-beta2-56769-src
  • Theme: twentytwentythree v1.2
  • Active Plugins:
    • gutenberg v16.8.0-rc.1
  • macOS System Settings > Appearance > Show scroll bars set to "Automatically based on mouse or trackpad"

Actual Results

  • ✅ When browser window is sized between ~1093 <> 1065, the Styles panel previews begin to shift around ("dance").

Additional Information

  • Just noting here that I did not experience this bug on the right-hand side of the editor under global Styles > Browse styles sidebar.

Supplemental Artifacts

Figure 1: Demonstration of browser window height effect on Styles variations previews.

dancing styles

@ironprogrammer ironprogrammer removed the Needs Testing Needs further testing to be confirmed. label Oct 6, 2023
@andrewserong
Copy link
Contributor

What a hilariously inconvenient bug! 😅

I didn't get a chance to look into a fix today, but I think I've found the cause:

In the sidebar we currently use scrollbar-gutter: stable which reserves space to the right edge of the secondary sidebar, that is, the space where a scrollbar would usually appear. This prevents the UI from jumping when a scrollbar becomes present:

The trouble is, that CSS property is not available in Safari: https://caniuse.com/mdn-css_properties_scrollbar-gutter so on Safari when a scrollbar appears, the width of the content area of the sidebar will be reduced. Then, over in the preview for each of these styles, there's a useResizeObserver that checks how wide the current container is, and then determines the ratio to use for the preview based on that width:

const [ containerResizeListener, { width } ] = useResizeObserver();

Then, that ratio is applied to the preview, affecting how tall each of those previews are. I think the endless cycle (or dancing effect) is a result of the following, though I'm not 100% sure which event occurs first:

  1. The sidebar is rendered without any previews
  2. Enough previews are rendered to cause a scrollbar to appear
  3. The presence of the scrollbar causes the sizes of the previews to be recalculated
  4. The previews are re-rendered, and now that they're smaller, result in no scrollbar being present
  5. As no scrollbar is present, the container is now wider, so the previews can be rendered larger again
  6. The previews are rendered larger, which introduces the scrollbar (we are now back at step 2, so the rest is an infinite loop)

So, for anyone looking into this issue, to reproduce, you'll need to:

  • Use Safari browser
  • A browser window that's the perfect height for the above loop to occur

I'm not too sure what the ideal fix would be here — I suspect either somewhere in preview.js, or we might do with a max-width on the container for the previews that factors in the possibility of a sidebar.

If no-one beats me to it, I can look into potential fixes tomorrow!

@lukecarbis
Copy link
Contributor Author

Thank you @andrewserong!

@andrewserong
Copy link
Contributor

Pleasure, thank you for reporting it @lukecarbis! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants