Conversation
| * editor scripts in order to override default block functionality | ||
| */ | ||
| add_action( 'enqueue_block_editor_assets', function (): void { | ||
| add_action( 'enqueue_block_assets', function (): void { |
There was a problem hiding this comment.
this always makes me nervous. every time we update this action, we end up needing the _assets one somewhere else (or the other way around). 😂
dpellenwood
left a comment
There was a problem hiding this comment.
I'm good with these changes as long as it doesn't prevent WP's internal inlining and conditional loading of scripts & styles on the FE. If we revert to always loading all scripts & styles for ever block, regardless of if the block is currently in the view or not, we will get dinged on performance scores for unused css/js on the page.
|
@dpellenwood You're right - I remembered the original reason we were doing it like we were doing, but for some reason this had stopped working. I've come up with a version now that should handle both instances while still allowing our styles to properly load in the editor. Let me know what you think. |
What does this do/fix?
This pull request updates how assets (scripts and styles) for core blocks are enqueued, ensuring that both frontend and editor environments render block styles and scripts consistently. The changes standardize asset handling and fix previous inconsistencies, especially around when and where styles and scripts are loaded.
Asset Enqueuing Improvements:
enqueue_core_block_public_styles,enqueue_core_block_editor_styles, andenqueue_core_block_editor_scriptsinBlock_Base.phpto usewp_enqueue_styleandwp_enqueue_scriptwith consistent naming and versioning, ensuring proper loading in both frontend and editor. Editor styles and scripts are now only enqueued in the admin/editor context. [1] [2]Blocks_Subscriber.phpfromadmin_initandenqueue_block_editor_assetstoenqueue_block_assetsfor enqueuing both public and editor assets for core blocks, ensuring they are available in both contexts as needed.Documentation:
CHANGELOG.mdto note that asset enqueuing for core blocks now allows block scripts and styles to properly render across both the frontend and editor.QA
Links to relevant issues
Screenshots/video:
Pull request checklist