[wp-trac] [WordPress Trac] #53505: `wp_should_load_separate_core_block_assets()` is confusing
WordPress Trac
noreply at wordpress.org
Fri Jun 25 07:22:38 UTC 2021
#53505: `wp_should_load_separate_core_block_assets()` is confusing
---------------------------+---------------------
Reporter: desrosj | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 5.8
Component: Script Loader | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
---------------------------+---------------------
Comment (by aristath):
I agree that the function-name is not perfect and could be improved,
suggestions are welcomed.
Since I see in a few Slack conversations & tickets there's some confusion
regarding what the function does, I'll post some details below cause it's
admittedly not easy.
Currently, the implementation deals mostly with stylesheets but the plan
is to expand the behavior to scripts - which is why it's using the term
`assets` and not `styles` in its name.
The goal is to have sites that only load the scripts and styles they need
instead of monolithic, large assets, therefore improving performance &
sustainability.
== What the function does:
=== Editor
On the editor it doesn't really make a difference and things work as they
did prior to 5.8. Nothin changes there for backwards-compatibility
reasons.
=== Frontend
On the frontend:
* If `wp_should_load_separate_core_block_assets` is `true`:
* `style.css` becomes `common.css` (does not contain block styles)
* Core blocks only load their styles on-render, and each block loads its
own, individual stylesheet.
* 3rd-party blocks only load their styles when rendered.
* If `wp_should_load_separate_core_block_assets` is `false`: Everything
works exactly as it did in WP 5.7
* All core block styles get loaded regardless of whether they are
rendered in a page or not, because they are all part of the `style.css`
file.
* 3rd-party blocks always get enqueued regardless of whether they are
rendered or not.
Setting `wp_should_load_separate_core_block_assets` to `false` (which is
the default) doesn't change anything, and things work exactly the way they
did prior to WP 5.8. The reason this was done is compatibility with
themes, as setting the value to `true` changes the loading order of styles
and themes may need to change some of their styles to make them more
specific. So this is opt-in for classic themes, as they will need to test
it and possibly tweak some styles.
-------------------
== Backtracking where the function is used and how:
=== `register_block_style_handle`: (Runs both in frontend and backend)
Skips registering styles for core-only blocks when
`should_load_separate_core_block_assets` is `false`. Since
`wp_should_load_separate_core_block_assets` checks for `is_admin()`, core
blocks won't register their separate styles in the editor and therefore
separate styles won't be enqueued, making this change only apply to the
frontend.
=== `wp_default_styles`: (Runs both in frontend and backend)
Changes the URL of the `block-library` stylesheet from `style.css` to
`common.css`.
Since `wp_should_load_separate_core_block_assets` checks for `is_admin()`,
this change will only happen on the frontend.
=== `wp_enqueue_registered_block_scripts_and_styles`: (Runs both in
frontend and backend)
* Frontend
* If `wp_should_load_separate_core_block_assets` is `true`, then styles
both for core & 3rd-party blocks get enqueued on `render_block`. The check
in this function ensures that we exit early and therefore these styles
won't always get enqueued, but instead will only be enqueued on-render.
* If `wp_should_load_separate_core_block_assets` is `false`, then styles
get enqueued. Core blocks haven't been registered because they get skipped
in `register_block_style_handle` so only 3rd-party block styles get
enqueued. This makes 3rd-party blocks styles always be enqueued - just
like it was prior to WP5.8.
* Editor
* `wp_should_load_separate_core_block_assets` is `false`, so only 3rd-
party block styles get enqueued. Core block styles are included in the
main `style.css` file - just like it was prior to WP5.8.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53505#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list