gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

In the block theme, I see a page with no styles applied for a moment.

Open iidastudio opened this issue 4 years ago • 9 comments

Description

In the block theme, When I view the page, I see a page with no styles applied for a moment. I think the cause is that the block theme inserts the style generated from theme.json (global-styles-inline-css) just before the closing tag of the body.

Step-by-step reproduction instructions

  1. Install WordPress 5.9
  2. Change the theme to twenty twenty two and other block themes.
  3. Browse the site (super reload).
  4. Check with the Classic theme for comparison. If your transmission speed is too fast, you may not be able to check.

Screenshots, screen recording, code snippet

https://user-images.githubusercontent.com/43173384/152102766-d7c5c927-e868-4d8a-91f4-89578b26ddf1.mov

Environment info

wp-env WordPress 5.9 Gutenberg 12.4.1 or Gutenberg Disable chrome

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

iidastudio avatar Feb 02 '22 07:02 iidastudio

Hey, I can repro this and will look into it. Thanks for reporting.

This is what I know so far: in WordPress 5.8 we introduced a mechanism to only load the CSS of blocks in use. AFAIK, that required a change for classic themes that opted-in into this mechanism, and the styles loaded at the bottom of the body for them. In the other cases (classic that didn't opt-in or block themes) the styles would still be loaded in the <head>. See core ticket https://core.trac.wordpress.org/ticket/53494#comment:8

Somehow, in WordPress 5.9, we've regressed this and they always load in the footer of the body for block themes as well.

oandregal avatar Feb 11 '22 10:02 oandregal

Prepared a fix for WordPress core at https://github.com/WordPress/wordpress-develop/pull/2303 linked to the trac issue https://core.trac.wordpress.org/ticket/53494#comment:40

oandregal avatar Feb 11 '22 11:02 oandregal

@oandregal Thanks for opening the fix, this indeed fixes the layout shift due to the "global styles" stylesheet, but there's still a layout shift due to the block supports styles. Should we update these as well?

Also, would be great if we can test this change in the Gutenberg plugin.

youknowriad avatar Feb 11 '22 11:02 youknowriad

Fix for loading global-styles-inline-css in Gutenberg properly at https://github.com/WordPress/gutenberg/pull/38745

oandregal avatar Feb 11 '22 13:02 oandregal

@youknowriad yeah, the PRs above don't fix the issue completely. I need to look at the block styles (layout+elements) separately.

oandregal avatar Feb 11 '22 13:02 oandregal

Gutenberg PR for loading block styles (layout & element) in the head https://github.com/WordPress/gutenberg/pull/38750

oandregal avatar Feb 11 '22 16:02 oandregal

The two PRs for Gutenberg have landed. I've done a number of tests that boil down to count the layout shift of the page.

These are the recorded screenshots from simulating a "slow 3G" without cache (as reported by Chrome's "Network" tab):

Before After
Captura de ecrã de 2022-02-16 17-13-18 Captura de ecrã de 2022-02-16 17-05-50

There's no longer any layout shift (as reported by Chrome's performance tab):

Before After
Captura de ecrã de 2022-02-16 17-36-17 Captura de ecrã de 2022-02-16 17-36-29

And the performance core web vital has improved significantly. See Cumulative Layout Shift, in particular. The report is for desktop:

Before After
Captura de ecrã de 2022-02-16 17-38-39 Captura de ecrã de 2022-02-16 17-38-30

oandregal avatar Feb 16 '22 16:02 oandregal

@iidastudio would you be able to test with Gutenberg from trunk and report back if it fixes the issue for you?

oandregal avatar Feb 16 '22 16:02 oandregal

I'm going to close this issue for now. Thanks for you work André

youknowriad avatar Feb 17 '22 10:02 youknowriad