Skip to content

[MOOSE-357] FE: Core Block Asset Enqueuing#330

Open
GeoffDusome wants to merge 2 commits intomainfrom
feature/MOOSE-357/fix-block-editor-enqueuing
Open

[MOOSE-357] FE: Core Block Asset Enqueuing#330
GeoffDusome wants to merge 2 commits intomainfrom
feature/MOOSE-357/fix-block-editor-enqueuing

Conversation

@GeoffDusome
Copy link
Copy Markdown
Contributor

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:

  • Refactored enqueue_core_block_public_styles, enqueue_core_block_editor_styles, and enqueue_core_block_editor_scripts in Block_Base.php to use wp_enqueue_style and wp_enqueue_script with 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]
  • Changed the action hook in Blocks_Subscriber.php from admin_init and enqueue_block_editor_assets to enqueue_block_assets for enqueuing both public and editor assets for core blocks, ensuring they are available in both contexts as needed.

Documentation:

  • Updated the CHANGELOG.md to 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

  • I've added a changelog entry for these changes.
  • I've linked to a relevant Jira issue.
  • I've captured a screenshot or screencast of the changes and linked it above.

Copy link
Copy Markdown
Contributor

@Vinsanity Vinsanity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢

* editor scripts in order to override default block functionality
*/
add_action( 'enqueue_block_editor_assets', function (): void {
add_action( 'enqueue_block_assets', function (): void {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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). 😂

Copy link
Copy Markdown
Contributor

@jamiepaul jamiepaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢

Copy link
Copy Markdown
Collaborator

@dpellenwood dpellenwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@GeoffDusome
Copy link
Copy Markdown
Contributor Author

@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.

cc @jamiepaul @Vinsanity

Copy link
Copy Markdown
Collaborator

@dpellenwood dpellenwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Launch Environment Deploys to dokku

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants