-
Notifications
You must be signed in to change notification settings - Fork 219
Fix compatibility between the checkout block and the template editor. #9495
Conversation
…epending on admin vs frontend
The release ZIP for this PR is accessible via:
Script Dependencies ReportThere is no changed script dependency between this branch and trunk. This comment was automatically generated by the TypeScript Errors Report
🎉 🎉 This PR does not introduce new TS errors. |
Size Change: 0 B Total Size: 1.08 MB ℹ️ View Unchanged
|
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.
Nice work! Thank you for working on this and for the explanation!
I found that (with the help of @senadir) this was due to wcBlocksConfig being missing when viewing the template editor. Eventually I found that we were rendering 2 wcSettings objects in the template editor, and one of them was missing wcBlocksConfig.
When you can, could you explain how you debug this?
I think that we can close this issue #9354
Nothing special tbh; trial, error, and viewing source is where I noticed the two wcSettings objects defined. |
It should be noted that we went into an iframe vs main context rabbit hole, for future debuggers, that's unrelated. All JS in the template editor is run on the mainframe, only the final HTML is rendered in the iframe (via portals). |
This PR fixes a conflict between block assets and the template editor. It reverts the change in #9332 and instead enqueues assets in the correct place.
To replicate the original issue:
This was a total pain to debug but to summarise, the fix in #9332 broke payment methods when editing the checkout block in the template editor. Payment method scripts were dequeued because the
wc-settings
hook dependency was not registered soon enough.verify_payment_methods_dependencies
removes payment method scripts if a dependency is missing to avoid breaking the main checkout block.Therefore I have reverted the #9332 change.
Reverting #9332 reintroduced the issue it fixed; broken image urls. I found that (with the help of @senadir) this was due to
wcBlocksConfig
being missing when viewing the template editor. Eventually I found that we were rendering 2wcSettings
objects in the template editor, and one of them was missingwcBlocksConfig
.If you look at the changes in https://github.com/WordPress/gutenberg/pull/49655/files, you can see that the template editor calls
wp_print_footer_scripts
. This was the problem. We enqueue asset data on 2 hooks:wp_print_footer_scripts
for the frontend.admin_print_footer_scripts
for the admin.So in this context we should only be using
admin_print_footer_scripts
to avoid the duplication. Adding a simpleis_admin
check resolves the issue.Reverts #9332
Fixes #9331
Testing
Confirm that the payment methods and shipping methods are rendered correctly, and image previews (cart items) are shown for the following test cases:
Template Editor
Page Editor
Without Gutenberg
WooCommerce Visibility
Changelog