#56923 closed defect (bug) (fixed)
register_block_core_template_part does WP_Query even on themes that do not support it
Reported by: | spacedmonkey | Owned by: | desrosj |
---|---|---|---|
Milestone: | 6.1.1 | Priority: | high |
Severity: | normal | Version: | 6.1 |
Component: | Themes | Keywords: | close |
Focuses: | performance | Cc: |
Description (last modified by )
register_block_core_template_part
functions calls, build_template_part_block_variations
-> build_template_part_block_instance_variations
->
get_block_templates
.
This calls WP_Query
and gets ALL posts of post type wp_template_part
. This happens on classic themes that do not even support theme parts.
Attachments (1)
Change History (15)
#2
@
2 years ago
- Description modified (diff)
- Keywords has-patch added
- Milestone changed from Awaiting Review to 6.1.1
- Priority changed from normal to high
Someone from the release squad could move this to the 6.1 milestone, but I can put in the minor.
Adding that condition removes the extra query from Twenty Seventeen.
The build_template_part_block_instance_variations()
function was introduced in r54257.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
2 years ago
#4
@
2 years ago
This WP_Query
is invoked before template_redirect
, so template parts are requested before we even know what kind of template we're dealing with.
Succinctly, I expect filters pre_get_posts
/ the_posts
not to be queried before action wp_loaded
. I think this premature registration is harmful, not only because it now creates bugs (CPTs aren't registered before the first query happens), but it causes significant performance losses.
#5
@
2 years ago
- Keywords commit added
My PR #45362 has been merged. This patch needed to ported from gutenberg to core. CC @mamaduka
#6
@
2 years ago
There's no need for porting. PHP files from the block-library
package are included during the build.
I just need to cherry-pick the changes.
#7
@
2 years ago
@Cybr Are you able to open a ticket to move register_block_core_template_part
to run later in the bootstrapping process. Whether that's later on the init hook or moving it to another hook is best for a dedicated ticket.
#8
@
2 years ago
@peterwilsoncc I think registering stuff at init
is fair. Though, I also think using WP Query before template_redirect
isn't, let alone misusing the Post Types API et co for stuff that isn't a Post Type.
In that, I think wp_template's foundation should be rewritten without considering Post Types but instead something bespoke --- perhaps having a new database table if deemed necessary. I believe this issue (45601) is already looking into that, but without noting the severity or scope of the cause.
I'm confident the Post Type API eased the integration for storing and filtering, but it shouldn't be deemed a long-term strategy. Elementor's recklessness is still haunting me; please don't let Gutenberg catch up to them.
#9
@
2 years ago
@Cybr @peterwilsoncc
The issue here, is that the WP_QUery is run on all requests, even when they are not needed. They are only needed in the site editor. I have created a ticket to fix this issue here. This involves loading the variants only when needed. This is a big change and is unlikely to make into a point release sadly.
#10
@
2 years ago
- Keywords close added; commit removed
- Version changed from trunk to 6.1
Marking this as close
because the this will be fixed when the block-library
package is updated prior to 6.1.1 RC later this week.
Screenshot from 2017 theme.