Opened 3 years ago
Last modified 2 years ago
#55902 new defect (bug)
Block theme rendering issue
Reported by: | jivansoft | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | blocker | Version: | |
Component: | Themes | Keywords: | needs-patch |
Focuses: | template | Cc: |
Description (last modified by )
Hi,
I am from Pagelayer team.
And we have checked and found that in the wp-includes/template-canvas.php
file, you have called the function get_the_block_template_html()
above the header that breaks the flow of the calling hooks like (get_header
, wp_enqueue_scripts
, wp_header
).
For example, If we add any the_content
hook inside the wp_enqueue_scripts
hook, then the the_content
hook not working properly.
Please check and try fix the issue ASAP if possible.
Change History (5)
#2
@
2 years ago
We have also noticed this problem. Because of the order the hooks are executed in block-based themes, enqueing a script during the page output (e.g. the_content
) happens before wp_enqueue_scripts
has run, so the script isn't registered. In normal template based themes, the order of standard WordPress actions goes:
template_redirect get_header wp_head wp_enqueue_scripts enqueue_block_assets wp_print_styles wp_print_scripts ...etc loop_start the_post
With block-based FSE themes, the order changes to:
template_redirect render_block_core_template_part_file loop_start the_post ...etc wp_head wp_enqueue_scripts enqueue_block_assets wp_print_styles wp_print_scripts
Therefore any scripts enqueued during the_content
or during shortcode callbacks (such as page specific scripts that are only required on that page) fall into the $queued_before_register
fallback provided in WP_Dependencies
. This mechanism handles any scripts enqueued before they were registered. The only reason the scripts enqueued during the_content
are loaded at all is because of this fallback.
I would suggest that core behaviour in block themes shouldn't be relying on this fallback. This could be fixed by changing the order of the main post hooks so that the_head
is called before the_content
as it is in regular template themes.
There is also an additional knock-on affect for themes & plugins which add inline script data (e.g. wp_add_inline_script
) during the_content
, as reported in #54958. I believe both issues would be resolved by changing the order of the hooks for block-based themes.
#55901 was marked as a duplicate.