[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

WordPress Trac noreply at wordpress.org
Fri Feb 14 18:37:04 UTC 2025


#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:  flixos90
     Type:  enhancement               |      Status:  closed
 Priority:  normal                    |   Milestone:  6.8
Component:  Editor                    |     Version:
 Severity:  normal                    |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+-----------------------
Changes (by flixos90):

 * status:  assigned => closed
 * resolution:   => fixed


Comment:

 In [changeset:"59823" 59823]:
 {{{
 #!CommitTicketReference repository="" revision="59823"
 Editor: Introduce `wp_should_load_block_assets_on_demand()` with filter
 `'should_load_block_assets_on_demand'`.

 This function and filter complement the existing
 `wp_should_load_separate_core_block_assets()` with filter
 `'should_load_separate_core_block_assets'`, which until now was
 responsible for two different purposes:
 1. Loading separate stylesheets for Core blocks, instead of a combined
 `wp-block-library` stylesheet (as the name indicates).
 2. Loading block scripts and stylesheets on demand only if the blocks are
 included in the page (not indicated by the name).

 The new function and filter handles exclusively the 2nd purpose, making it
 possible to individually adjust both behaviors. For backward
 compatibility, the return value of
 `wp_should_load_separate_core_block_assets()` is used as the filterable
 default for `wp_should_load_block_assets_on_demand()`. Yet, the two
 filters can now be individually be controlled: For example, a site owner
 that wants to keep loading the combined `wp-block-library` stylesheet can
 now do so without giving up on the ability to load block scripts and
 stylesheets on demand.

 Block themes now opt in by default to both features, similar to how they
 were already doing before via just the one filter. This way, block themes
 that opt out of loading separate stylesheets for Core blocks will still
 benefit from loading block scripts and stylesheets on demand, which in the
 case of block themes is strongly recommended.

 Props fabiankaegy, flixos90, gziolo.
 Fixes #61965.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61965#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list