[wp-trac] [WordPress Trac] #61965: Provide a way for classic themes to use `wp-block-library` even when loading block assets only for blocks that actually render on a page (was: Provide a way for classic themes to opt into only loading styles for 3rd party blocks that actually render on a page)
WordPress Trac
noreply at wordpress.org
Fri Aug 30 16:12:23 UTC 2024
#61965: Provide a way for classic themes to use `wp-block-library` even when
loading block assets only for blocks that actually render on a page
-------------------------+------------------------------
Reporter: fabiankaegy | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
-------------------------+------------------------------
Comment (by flixos90):
@fabiankaegy Thanks for confirming. I'll rename the ticket to clarify.
A potential solution for this could be (I'm not going to talk about
function names so that we can focus on the solution only):
* There's a function (and filter) "A" that controls whether to load block
assets on demand (we already have that today).
* There could be another function (and filter) "B" that controls whether
to use individual core block stylesheets instead of `wp-block-library`.
* While today's function name sounds like it would do that, that's not
actually its primary purpose (see #61958).
* Function "B" would by default rely on the output of function "A". In
other words: If block assets are loaded on demand, individual core block
stylesheets are used. But the filter in "B" could be used to change that,
without changing the output of function "A".
* With this kind of setup, everything would work the same way as today by
default. The enhancement though would be that you can change the two
configurations independently of each other.
The two new possible scenarios that aren't supported in Core today would
be:
* Block assets are loaded on demand, but `wp-block-library` is used: In
this scenario, whenever any core blocks is encountered, the `wp-block-
library` stylesheet would be enqueued.
* Block assets are loaded unconditionally, but individual core block
stylesheets are used: In this scenario, the individual core block
stylesheets would simply be enqueued everywhere.
I don't feel strongly about whether or not it's a good idea to support
this. Generally, using `wp-block-library` is wasteful when it comes to
performance (and sustainability). But I acknowledge that lots of third-
party code depends on `wp-block-library` today and it'll take time to
migrate away from that. When in that situation, today you will ''have'' to
load all block assets everywhere, even third party blocks that have
nothing to do with `wp-block-library`. Essentially, today Core only allows
you to go all in or get none of the benefits of loading on demand. So
differentiating between whether to load block assets on demand and whether
to use `wp-block-library` might be a worthwhile enhancement.
@gziolo @aristath I'd be curious to get your perspective.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61965#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list