[wp-trac] [WordPress Trac] #55902: Block theme rendering issue

WordPress Trac noreply at wordpress.org
Thu Jul 21 12:40:31 UTC 2022


#55902: Block theme rendering issue
-------------------------------+------------------------------
 Reporter:  jivansoft          |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  General            |     Version:
 Severity:  blocker            |  Resolution:
 Keywords:  changes-requested  |     Focuses:  template
-------------------------------+------------------------------

Comment (by andykeith):

 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.

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


More information about the wp-trac mailing list