Skip to content

Lazy Editor: Fix Media Library loading#73176

Merged
youknowriad merged 1 commit intotrunkfrom
fix/media-library
Nov 13, 2025
Merged

Lazy Editor: Fix Media Library loading#73176
youknowriad merged 1 commit intotrunkfrom
fix/media-library

Conversation

@youknowriad
Copy link
Contributor

What?

Related #72982

When trying to load the editor lazily, it needs the media library for the media upload buttons... The issue though is that the media library scripts need html templates to function properly. So this PR loads the scripts and the templates.

Testing Instructions

@youknowriad youknowriad requested a review from jsnajdr November 11, 2025 21:55
@youknowriad youknowriad self-assigned this Nov 11, 2025
@youknowriad youknowriad added the [Type] Experimental Experimental feature or API. label Nov 11, 2025
@github-actions
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: youknowriad <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@youknowriad
Copy link
Contributor Author

Going to merge this to fix the issues, but we can iterate on it later. I'd appreciate if you can look @jsnajdr when you have time.

@youknowriad youknowriad merged commit 1a8b662 into trunk Nov 13, 2025
40 checks passed
@youknowriad youknowriad deleted the fix/media-library branch November 13, 2025 12:32
@github-actions github-actions bot added this to the Gutenberg 22.2 milestone Nov 13, 2025
@jsnajdr
Copy link
Member

jsnajdr commented Nov 13, 2025

If all we need are really just the templates and nothing else, we could call wp_print_media_templates instead of wp_enqueue_media. wp_print_media_templates is a big and boring function that just prints a lot of static HTML. On the other hand, wp_enqueue_media is quite complex.

I can try out if the boot page continues to be fixed with that simplification.

@youknowriad
Copy link
Contributor Author

AFAIK, we need to enqueue the scripts as well and the scripts make use of the templates.

@jsnajdr
Copy link
Member

jsnajdr commented Nov 13, 2025

In that case this current implementation is probably the best we can do, I don't immediately see a better/simpler way to do it.

The site-editor.php and edit-form-blocks.php pages in Core, the ones that load Gutenberg, also call wp_enqueue_media.

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

Labels

[Type] Experimental Experimental feature or API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants