-
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
Blocks: Add handling for block.json viewModule #57437
Conversation
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/experimental/modules/class-gutenberg-modules.php |
37e636d
to
56a3d3c
Compare
This reverts commit 07fc04e64149c70606417ac288bffc648ca4816a.
56a3d3c
to
3fd6278
Compare
Flaky tests detected in 3fd6278. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7415313014
|
Squashed commit of the following: commit 3fd6278 Author: Jon Surrell <sirreal@users.noreply.github.com> Date: Fri Dec 29 15:19:57 2023 +0100 Comment out useles i18n code commit 2fdf006 Author: Jon Surrell <sirreal@users.noreply.github.com> Date: Fri Dec 29 15:19:44 2023 +0100 Fix lints commit 4f7d640 Author: Jon Surrell <sirreal@users.noreply.github.com> Date: Fri Dec 29 15:19:31 2023 +0100 Reuse translation from core commit 6594c16 Author: Jon Surrell <sirreal@users.noreply.github.com> Date: Thu Dec 28 21:13:43 2023 +0100 Fix lints commit 58c66d8 Author: Jon Surrell <sirreal@users.noreply.github.com> Date: Thu Dec 28 21:10:22 2023 +0100 Use existing filter over new action This is really an action (side effect) but we don't need to add a new action if we use the filter commit 7bcb68a Author: Jon Surrell <sirreal@users.noreply.github.com> Date: Thu Dec 28 20:59:05 2023 +0100 Working implementation with caveats
fc1fdf3
to
34b5b44
Compare
This reverts commit 34b5b44.
I reverted the |
@luisherranz Any preference for how we handle the dev note? Are there other announcements around modules and Interactivity that go together? |
I've never done a dev note so I have no idea 😄 But the Interactivity API and Modules API should be announced separately. It happens that the Interactivity API will use the Modules API, but they are conceptually separate things. |
Support `viewScriptModule` block.json field for registering blocks from metadata. #57437 added `viewModule` support, but the Modules API changed in core to refer to "script modules." --- - `viewModule` is deprecated but supported. - `viewScriptModule` support is added. If both fields are present, `viewScriptModule` will be used. Two REST API fields are included for block types with the same information. `view_module_ids` (deprecated) and `view_script_module_ids`.
Syncing changes from the Gutenberg plugin: WordPress/gutenberg#57437. Scripts and styles can be registered for blocks via `block.json` metadata. There is now a Modules API, but was no way to register or associate module assets with blocks via `block.json`. Fixes #60233. Props jonsurrell, gziolo, cbravobernal, luisherranz, youknowriad. git-svn-id: https://develop.svn.wordpress.org/trunk@57565 602fd350-edb4-49c9-b593-d223f7449a82
Syncing changes from the Gutenberg plugin: WordPress/gutenberg#57437. Scripts and styles can be registered for blocks via `block.json` metadata. There is now a Modules API, but was no way to register or associate module assets with blocks via `block.json`. Fixes #60233. Props jonsurrell, gziolo, cbravobernal, luisherranz, youknowriad. Built from https://develop.svn.wordpress.org/trunk@57565 git-svn-id: http://core.svn.wordpress.org/trunk@57066 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Syncing changes from the Gutenberg plugin: WordPress/gutenberg#57437. Scripts and styles can be registered for blocks via `block.json` metadata. There is now a Modules API, but was no way to register or associate module assets with blocks via `block.json`. Fixes #60233. Props jonsurrell, gziolo, cbravobernal, luisherranz, youknowriad. Built from https://develop.svn.wordpress.org/trunk@57565 git-svn-id: https://core.svn.wordpress.org/trunk@57066 1a063a9b-81f0-0310-95a4-ce76da25c4cd
What?
Add
viewModule
support for registering blocks from metadata.Part of #57492
To do:
Why?
As we introduce module support and the Interactivity API (only available as a module at this time), we should provide at least a similar experience to what we currently have with scripts.
How?
This follows a similar pattern to how WordPress Core manages block scripts. Different script handles are attached to the WP_Block_Type instance. Then those are enqueued when the block is rendered.
We use some filters to achieve the same result. I'd expect this functionality to move to Core when Modules support lands (WordPress/wordpress-develop#5818). See sirreal/wordpress-develop#2 for an example of what that might look like.
Testing Instructions
Add a block using
block.json
with aviewModule
field pointing to its view module. I've compiled a block (with #57461) that's available at this gist. It can be unzipped as a plugin and used for testing.We should be able to add our block in the editor. If we use the REST API to query block types and search for
view_module_ids
we should find our block:If the block is added to a post and we visit it on the frontend, we should see it working as expected (a counter in our example).
We should also see the expected modules added to the importmap and module preloads on our post with the block. I used an older theme to ensure nothing else was enqueuing the interactivity module: