In the block theme, I see a page with no styles applied for a moment.
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
- Install WordPress 5.9
- Change the theme to twenty twenty two and other block themes.
- Browse the site (super reload).
- 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
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.
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 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.
Fix for loading global-styles-inline-css in Gutenberg properly at https://github.com/WordPress/gutenberg/pull/38745
@youknowriad yeah, the PRs above don't fix the issue completely. I need to look at the block styles (layout+elements) separately.
Gutenberg PR for loading block styles (layout & element) in the head https://github.com/WordPress/gutenberg/pull/38750
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 |
|---|---|
![]() |
![]() |
There's no longer any layout shift (as reported by Chrome's performance tab):
| Before | After |
|---|---|
![]() |
![]() |
And the performance core web vital has improved significantly. See Cumulative Layout Shift, in particular. The report is for desktop:
| Before | After |
|---|---|
![]() |
![]() |
@iidastudio would you be able to test with Gutenberg from trunk and report back if it fixes the issue for you?
I'm going to close this issue for now. Thanks for you work André





