-
Notifications
You must be signed in to change notification settings - Fork 219
Fix wc-settings not loading when a script that depend on it is in the header #5059
Conversation
Size Change: 0 B Total Size: 1.11 MB ℹ️ View Unchanged
|
|
src/AssetsController.php
Outdated
@@ -38,6 +38,8 @@ protected function init() { | |||
add_action( 'body_class', array( $this, 'add_theme_body_class' ), 1 ); | |||
add_action( 'admin_body_class', array( $this, 'add_theme_body_class' ), 1 ); | |||
add_action( 'admin_enqueue_scripts', array( $this, 'update_block_style_dependencies' ), 20 ); | |||
add_action( 'wp_enqueue_scripts', array( $this, 'update_block_settings_dependencies' ), 1 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why priority 1 for these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, as this is your commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't recall adding it, it shouldn't be needed. If anything, it should be a late priority.
wp_add_inline_script( | ||
$error_handle, | ||
sprintf( 'console.warn( "%s" );', $error_message ) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question below. Everything else looks ok. Let @nielslange give final approval.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚢
63072c2
to
d60415a
Compare
@mikejolley this code seems to be running on all registered scripts, even the ones not enqueued on the current page. I'm seeing it on the checkout frontend for an editor script. I guess that's not something we can avoid? |
@senadir could try using |
|
We can try
|
Maybe it is queue. You can cross-reference the objects in |
… header (woocommerce#5059) * Enqueue in header if required. * revert scripts change * Dirty fix for settings dependency * Also implement in admin * add console warn * grammar issues * increase priority Co-authored-by: Mike Jolley <[email protected]>
… header (woocommerce#5059) * Enqueue in header if required. * revert scripts change * Dirty fix for settings dependency * Also implement in admin * add console warn * grammar issues * increase priority Co-authored-by: Mike Jolley <[email protected]>
@senadir Could you give some hints on how to act upon that warning? What is the recommended way to register a block in the footer? See https://github.com/woocommerce/automatewoo/issues/1304 |
If you're loading scripts using the block.json then it will load up in the header sadly, you will need to enqueue your scripts manually. |
@senadir or @mikejolley is this (showing a warning for blocks registering scripts via There's a couple things we might want to consider:
|
I'd need to look at this again to refresh memory, but I think we currently just dump a variable on the page with the settings object right? What if that were a callback that added the settings after initial load? I guess this could break some blocks/utils relying on settings being there on load however. |
Seeing this come up here with a user, letting them know not to worry about it. 7761451-zd-a8c |
This PR is cherry-picked from #5045
The goal of it is to fix an issue in which a script:
register_block_type( block.json )
for example).wc-settings
or something that depend on it likewc-blocks-checkout
,wc-price-format
.would break the page because
wc-settings
inline script would not load.This PR (by @mikejolley) fixes the issue by forcing scripts that depend on
wc-settings
to print in the footer.Testing steps
npx wp-create-block test-block
and include something from@woocommerce/blocks-checkout
or@woocommerce/price-format
.wc-settings
script enqueued.Changelog