-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Interactive template: Use viewModule #57712
Interactive template: Use viewModule #57712
Conversation
Size Change: +97 B (0%) Total Size: 1.69 MB
ℹ️ View Unchanged
|
27d4b71
to
a6b0670
Compare
- Add all files to the generated plugin zip. [#56943](https://github.com/WordPress/gutenberg/pull/56943) | ||
- Prevent crash when Gutenberg plugin is not installed. [#56941](https://github.com/WordPress/gutenberg/pull/56941) | ||
- Add all files to the generated plugin zip ([#56943](https://github.com/WordPress/gutenberg/pull/56943)). | ||
- Prevent crash when Gutenberg plugin is not installed ([#56941](https://github.com/WordPress/gutenberg/pull/56941)). |
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.
Most other CHANGELOGs in the repo follow this form so I updated these.
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 🙂🎉
I removed the manual calls to register and enqueue.
if ( defined( 'GUTENBERG_VERSION' ) && version_compare( GUTENBERG_VERSION, '17.5', '>=' ) ) { | ||
register_block_type_from_metadata( __DIR__ . '/build' ); | ||
return; | ||
} |
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.
What's this for?
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.
The viewModule
support for registering blocks via metadata is only going to be available in the upcoming Gutenberg release (17.5
), so I thought we should gate the way we register the block on the Gutenberg version, otherwise we should manually register the view module.
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.
This was intended to work with the following block, we should either drop the conditional here, or revert the commit that removes the manual module registration.
The metadata registration won't work prior to Gutenberg 17.5 for viewModule.
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.
Ok, thank you.
This template already requires GB 17.2, so why not update it to require 17.5. After all, is just a way to get started with the Interactivity API, so requiring the latest version of Gutenberg makes sense.
I've pushed a commit with the changes but please review it yourself as well 🙂
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.
That seems fine to me 👍 although we will have a window where we require an unreleased Gutenberg version. Maybe we can dist-tag the previous version of this package as latest until 17.5 is released.
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.
It's one week only, I think it's fine.
I tested your additional changes and they're working @luisherranz. Thanks! |
What?
Use
viewModule
in the create-block interactivity template.Why?
Part of #57492
We should use the new
viewModule
functionality as the preferred way for working with modules and the interactivity API.How?
We add
viewModule
support to@wordpress/create-block
.We set the
--experimental-modules
option when building the tempalted block (see #57461).The plugin php template is updated to register with block metadata.
Testing Instructions
Check this out, ensure packages are up to date (
npm ci
), then from another directory run:Note that the above will fail to build. We need to change the generate
package.json
to point to the unreleased wp-scripts package (and we'll need to include another dependency):Then we can
npm i
andnpm run build
. We can install out plugin in a local WordPress installation or inspect the build output:build/block.json
If we test using a local WordPress install running the latest
trunk
version of Gutenberg, note that we won't hit this condition. We should be sure to setGUTENBERG_VERSION
in our built Gutenberg plugin'sgutenberg.php
:Ensure that the block works in the editor and the frontend when we don't satisfy that condition. Then add this to
gutenberg.php
to be sure we hit the condition and confirm the block still works as expected: