[wp-trac] [WordPress Trac] #58075: wp_enqueue_scripts action not firing at the right time with block themes

WordPress Trac noreply at wordpress.org
Fri May 26 09:44:21 UTC 2023


#58075: wp_enqueue_scripts action not firing at the right time with block themes
---------------------------+------------------------------
 Reporter:  wprj           |       Owner:  (none)
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Script Loader  |     Version:  6.2
 Severity:  major          |  Resolution:
 Keywords:  needs-patch    |     Focuses:
---------------------------+------------------------------

Comment (by yashskukreja):

 @sabernhardt @wprj
 I think this is happening because of the fact that all the blocks are
 rendered and resolved first.
 As per the flow, all the blocks are resolved in locate_block_template()
 which sets up the block content. At this stage, the scripts aren't
 enqueued. This is the reason why when we are checking did_action() on the
 content, it shows 0.
 locate_block_template() returns the wp-include/template-canvas.php which
 added the HTML markup on our block content with wp_head() (which enqueues
 the scripts).

 Scripts do enqueue in the final template, which you can see by adding the
 following code in wp-include/template-canvas.php:

 {{{
 <?php echo $template_html; // phpcs:ignore WordPress.Security.EscapeOutput
 ?>

 <?php echo 'enqueued - ' . did_action( 'wp_enqueue_scripts' ); // Add this
 line ?>

 }}}

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


More information about the wp-trac mailing list