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

Mobile/Tablet/Desktop Previews do not work with externally loaded CSS #21193

Closed
roo2 opened this issue Mar 27, 2020 · 15 comments · Fixed by #33342 or #46212
Closed

Mobile/Tablet/Desktop Previews do not work with externally loaded CSS #21193

roo2 opened this issue Mar 27, 2020 · 15 comments · Fixed by #33342 or #46212
Assignees
Labels
[Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@roo2
Copy link
Contributor

roo2 commented Mar 27, 2020

Describe the bug
On wordpress.com we use stylesheets loaded from s0.wp.com, s1.wp.com for various plugins such as full-site-editing.
When we install the gutenberg plugin and use the mobile preview, some of the css still behaves as if in desktop mode, so we see columns on mobile preview etc.

image

To reproduce
Steps to reproduce the behavior:

  1. Install a plugin that loads styles from an external domain with mobile breakpoints (tested with the full-site-editing plugin)
  2. Open the gutenberg editor and attempt to mobile preview

Expected behavior
The columns should be stacked for mobile display. Preview should render as if in a mobile device.

Additional context
From our initial investigation, here is what appears to be happening:
Our current understanding of what's happening:

Mobile/tablet preview uses the use-simulated-media-query function which works by modifying the loaded stylesheets to simulate being viewed on mobile/tablet breakpoints.

This works for stylesheets loaded from the same domain. However, on wordpress.com, the static domains s0.wp.com and s1.wp.com are used to serve many stylesheets such as those from the full-site-editing-plugin.

These stylesheets are therefore rendered in desktop mode even when using mobile/tablet preview.

calypso issue: Automattic/wp-calypso#40401

@simison
Copy link
Member

simison commented Mar 27, 2020

Potential fix: #21102 cc @ellatrix

@ellatrix
Copy link
Member

Yes, this will be fixed with an iframe. The PR is almost ready.

@ddryo
Copy link
Contributor

ddryo commented Jul 20, 2020

Hello.
I am suffering from the same thing.

Media queries written in style sheets loaded by themes and plugins also do not work.

I'm using the 'enqueue_block_editor_assets' hook to read a CSS file. Is that OK?

@ddryo
Copy link
Contributor

ddryo commented Jul 20, 2020

Also, it would be nice to have a way to detect from CSS which device mode is currently being previewed.

It would be very helpful if something like the '.is-mobile-mode' class was added to the body tag.

For example, just like turning on fullscreen mode gives it the '.is-fullscreen-mode' class.

It is possible to adjust the style using those class names.

@Vanillabacke
Copy link

Also, it would be nice to have a way to detect from CSS which device mode is currently being previewed.

It would be very helpful if something like the '.is-mobile-mode' class was added to the body tag.

For example, just like turning on fullscreen mode gives it the '.is-fullscreen-mode' class.

It is possible to adjust the style using those class names.

I was opening an issue for that. It would be also nice to have an hook / event for it.
#23430

@roo2
Copy link
Contributor Author

roo2 commented Sep 4, 2020

this one was fixed in gutenberg

@roo2 roo2 closed this as completed Sep 4, 2020
@mreishus
Copy link
Contributor

mreishus commented Sep 18, 2020

I believe we're still seeing this issue in wordpress.com. Was this a recent fix that hasn't been released yet?

To reproduce:

  • Visit a site's wp-admin and create a new post.
  • Add a column block and set to 33/33/33
  • Add a paragraph block in each column and set a background color for it
  • Make your browser window wide and activate mobile preview mode

Expected result (works correctly when running off localhost with wp-env, or off sandbox):

  • Columns are stacked
  • In browser inspector, CSS media query breakpoints refer to 0px and 999999px (the rules on .wp-block-column )
  • This means useSimulatedMediaQuery ran correctly
  • Checking window.document.styleSheets shows href attributes that match the current site name, so getStyleSheetsThatMatchHostname() was able to find the stylesheets

2020-09-18_11-52-stacked

2020-09-18_12-46-sandbox-href

Actual result (wpcom):

  • Columns are side by side instead of stacked
  • In browser inspector, CSS media query breakpoints still refer to real numbers instead of 0 and 999999 (the rules on .wp-block-column )
  • This means useSimulatedMediaQuery did not run
  • Checking window.document.styleSheets shows href attributes that are mostly null, so getStyleSheetsThatMatchHostname() was not able to find the stylesheets

2020-09-18_13-13-side-by-side

2020-09-18_12-46_1-null-href

@simison simison reopened this Sep 19, 2020
@daviedR
Copy link
Contributor

daviedR commented Mar 5, 2021

Any update on this? Styling Gutenberg editor is really frustrating at this point.

@ellatrix
Copy link
Member

ellatrix commented Mar 5, 2021

We need the iframe the post editor. I need to look at this again, but honestly is a tough and frustrating job :) The iframe has landed in the side editor, so there's some light at the end of the tunnel. I'll resume work on this.

@fabiankaegy
Copy link
Member

@ellatrix If there is anything that can be done to support your efforts on that front let us know :) It is a great effort but I can only imaging how frustrating it must be... :)

@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Jul 10, 2021
@ellatrix
Copy link
Member

Should be fixed by #33342. We're planning for all previews to be iframed in the WP 5.9 release. The only thing that will remain without an iframe is the post editor without (or "Desktop") preview. This is to give plugin and theme authors time to check their blocks and update them if needed. This particular issue should be resolved though, because it's about the Tablet and Mobile previews.

@lukasz-gorski
Copy link

Should be fixed by #33342. We're planning for all previews to be iframed in the WP 5.9 release. The only thing that will remain without an iframe is the post editor without (or "Desktop") preview. This is to give plugin and theme authors time to check their blocks and update them if needed. This particular issue should be resolved though, because it's about the Tablet and Mobile previews.

So it have been a while and we have 5.9 ;) Does it's possible to enable iframe preview for Desktop too? I see it's not default, but maybe as an option somehow?

@vitaliikaplia
Copy link

same question here

is there any option to force iframe preview for desktop?

thanks! @ellatrix

@pawel-dabek
Copy link

Same question here.
I would like to force iframe for dekstop view too.

@ellatrix
Copy link
Member

Fixed by #48286

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet