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.
To reproduce
Steps to reproduce the behavior:
full-site-editing
plugin)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: https://github.com/Automattic/wp-calypso/issues/40401
Potential fix: https://github.com/WordPress/gutenberg/pull/21102 cc @ellatrix
Yes, this will be fixed with an iframe. The PR is almost ready.
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?
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.
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.
https://github.com/WordPress/gutenberg/issues/23430
this one was fixed in gutenberg
I believe we're still seeing this issue in wordpress.com. Was this a recent fix that hasn't been released yet?
To reproduce:
Expected result (works correctly when running off localhost with wp-env, or off sandbox):
.wp-block-column
)useSimulatedMediaQuery
ran correctlywindow.document.styleSheets
shows href
attributes that match the current site name, so getStyleSheetsThatMatchHostname()
was able to find the stylesheetsActual result (wpcom):
.wp-block-column
)useSimulatedMediaQuery
did not runwindow.document.styleSheets
shows href
attributes that are mostly null, so getStyleSheetsThatMatchHostname()
was not able to find the stylesheets
Most helpful comment
Yes, this will be fixed with an iframe. The PR is almost ready.