-
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 viewScriptModule #58731
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/script-modules.php |
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 Core SVNCore Committers: Use this line as a base for the props when committing in SVN:
GitHub Merge commitsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
I was looking at the current state of the feature in preparation for syncing changes with WordPress core. There are two more PRs to land in Gutenberg:
Is there a documentation in place similar to https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#view-script? The following section doesn’t play well with ES Modules, so some edits will be required: In general, documenting when and how to transition to |
Good spot, I'll add and update documentation in this PR. |
When this lands in core, the block.json schema will also need an update, but that file is served from GitHub so there's no realease deadline for that change. |
bc3b9ca
to
49b0d0a
Compare
I've pushed some updates to the documentation mentioned. |
Flaky tests detected in 49b0d0a. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7813292843
|
I think you need to edit this file, can be done in Gutenberg: |
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.
Tested and working as expected, both the enqueueing of the script module in the frontend and the new endpoint in the REST API 🙂
49b0d0a
to
287559d
Compare
👋 Hi @sirreal! Just a friendly reminder to manually review, update as needed, and include the If it was on accident, no big deal! But just trying to make sure everyone is aware as we retrain our brains. 😄 |
What?
Support
viewScriptModule
block.json field for registering blocks from metadata.Why?
#57437 added
viewModule
support, but the Modules API changed in core to refer to "script modules." We expect this field to land in core asviewScriptModule
(WordPress/wordpress-develop#5860).How?
viewModule
remains supported (but deprecated).viewScriptModule
support is added.If both fields are added,
viewScriptModule
will be used.We now have two REST API fields for block types with the same information.
view_module_ids
(deprecated) andview_script_module_ids
.Testing Instructions
Largely the same as #57437. Try these steps with
viewModule
,viewScriptModule
and both.Add a block using
block.json
with a (viewModule
,viewScriptModule
, both) 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: