Experiment: A Modules API with optional static server dependency graph#56118
Closed
luisherranz wants to merge 15 commits into
Closed
Experiment: A Modules API with optional static server dependency graph#56118luisherranz wants to merge 15 commits into
luisherranz wants to merge 15 commits into
Conversation
6 tasks
2 tasks
youknowriad
reviewed
Nov 16, 2023
| }, | ||
| externalsType: 'module', | ||
| externals: { | ||
| '@wordpress/interactivity': '@wordpress/interactivity', |
Contributor
There was a problem hiding this comment.
I think at some point in our config we need to maintain an esmodules array to keep these as is in the code (just like we have a dedicated config for bundled modules). I expect interactivity to be just one of these modules
Member
Author
There was a problem hiding this comment.
Yeah. I didn't pay much attention to the bundling side yet as it shouldn't affect the PHP API, so I just made it work 😄
(I'm not a fan of the code produced by Webpack for ES modules, by the way.)
youknowriad
reviewed
Nov 16, 2023
| } | ||
|
|
||
| add_action( 'wp_print_scripts', 'block_core_search_ensure_interactivity_dependency' ); | ||
| add_action( 'init', 'register_block_core_search' ); |
Contributor
There was a problem hiding this comment.
I really like how this simplifies the code of all these "interactive" blocks.
Member
|
This is now part of WordPress core 🎉 The final approach is documented in the dev note: Script Modules in 6.5. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Built on top of #56092.
This is the second of a series of experiments to understand the requirements of a hypothetical Modules API. More info in the Tracking Issue:
This experiment aims to implement an API that is slightly more complex than the one implemented in the first experiment, with the same characteristics but adding an optional static server dependency graph to be able to preload modules and avoid initial waterfalls:
<script>tag in the head.<link rel="modulepreload">tag in the head.Why?
In the first experiment, it's not easy to know which modules need to be preloaded and, therefore, it's not easy to avoid the initial waterfalls.
How?
By leveraging a new
Gutenberg_Modulesclass that acts as a singleton and a couple of functions to expose the functionality:gutenberg_register_moduleto register modules and add entries to the import map.gutenberg_enqueue_moduleto enqueue modules.Then, we print three times using the
wp_headaction:Testing Instructions
type="module"are loaded by the interactive blocks.@wordpress/interactivitymodule is loaded by the other modules usingimport ... from "@wordpress/interactivity".@wordpress/interactivitymodule is download at the same time than the rest (instead of after, like in the first experiment), and that there is a link tag withrel="modulepreload"in the head.