[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
Thu Jan 30 23:05:58 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:  assigned
 Priority:  normal                        |   Milestone:  6.8
Component:  General                       |     Version:
 Severity:  normal                        |  Resolution:
 Keywords:  needs-patch needs-unit-tests  |     Focuses:
------------------------------------------+-----------------------
Changes (by flixos90):

 * keywords:   => needs-patch needs-unit-tests


Comment:

 While related to my proposal in [comment:4] I proposed to rename
 (deprecate) the existing `wp_should_load_separate_core_block_assets()`
 function and the related filter in #61958, we can probably go a less
 disruptive route by implementing my idea from [comment:4] the other way
 around:

 * Today, `wp_should_load_separate_core_block_assets()` controls both
 whether to load separate block assets as well as whether to "lazy-load"
 block assets for only the blocks that are used in the current page.
 * To retain backward compatibility, we will need to retain that behavior.
 We can however introduce a new function, e.g.
 `wp_should_load_block_assets_on_demand()`, which would by default rely on
 the output of `wp_should_load_separate_core_block_assets()`, but could
 separately be modified via filter.
 * This new function will effectively allow use of the combined `wp-block-
 library` asset even while loading only block assets needed on the page. It
 would be achieved by filtering the result of
 `wp_should_load_separate_core_block_assets()` to `false` and filtering the
 result of `wp_should_load_block_assets_on_demand()` to `true`.

 Worth noting: I still think `wp_should_load_separate_core_block_assets()`
 is not a great name for the function, specifically the fact that it
 includes the word "core", but it's not at all specific to Core blocks. But
 renaming/deprecating the function would be quite disruptive, so that is a
 discussion for another time and another ticket.

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


More information about the wp-trac mailing list