-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new How-to Guide for enqueueing assets in the Editor. #53828
Conversation
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.
Thanks for compiling all this! :)
Flaky tests detected in 77eef3f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5913306149
|
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.
Great job simplifying and clarifying this, @ndiego!
Great job @ndiego! I think this page is a much-needed reference for this topic. As a suggestion, I would group the sections describing each scenario, under a parent group called "Scenarios for enqueuing " (or similar), resulting in a structure as follows:
Some practical examples could also be added to https://github.com/WordPress/gutenberg-examples and referenced from this page but that would be out of the scope of this PR |
Thanks @juanmaguitar, I have updated the heading structure accordingly.
This is a great idea. Definitely, something to add in the next iteration. |
|
||
This guide is designed to be the definitive reference for enqueueing assets (scripts and styles) in the Editor. The approaches outlined here represent the recommended practices but keep in mind that this resource will evolve as WordPress does. Updates are encouraged. | ||
|
||
As of WordPress 6.3, the Post Editor is iframed if all registered blocks have a [`Block API version 3`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/) or higher and no traditional metaboxes are registered. The Site Editor has always been iframed. This guide assumes you are looking to enqueue assets for the iframed Editor, but refer to the backward compatibility section below for additional considerations. |
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.
Worth noting that enqueuing assets to work for iframing should also work if the editor is not iframed, just not vice versa (things working without iframe will not necessarily work with the iframe).
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.
Thanks @ellatrix. I will add this note to the doc later this week. I have a few more minor tweaks to make.
I added a link to your page in https://make.wordpress.org/core/2023/07/18/miscellaneous-editor-changes-in-wordpress-6-3/#post-editor-iframed. |
I did always load SVG sprites with AJAX, this doesn't work anymore with iframed editor and i'm wondering if there's a better way to use SVG fragments inside Gutenberg? Sure, I could use some conditions and use the tricks mention in the new howto. Another problem is any script loaded with This was the code: function loadIcons() {
fetch( '/app/themes/custom/static/icons.svg' )
.then( ( response ) => response.text() )
.then( ( result ) =>
document.body.insertAdjacentHTML( 'afterbegin', result )
);
} |
What?
This PR adds a new How-to Guide in the Block Editor Handbook that details the best practices for enqueueing assets in the Editor.
Why?
Numerous dev notes, GitHub issues, and scattered articles discuss enqueueing assets in the Editor. This PR aims to house all that knowledge in one place so it can be easily referenced.
Note that this PR should be considered an initial iteration. There are many nuances and edge cases regarding enqueueing assets in the Editor. There are also a handful of open issues related to this topic (ex. #53590). Future updates will undoubtedly be needed.