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.
Most other CHANGELOGs in the repo follow this form so I updated these.
luisherranz
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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.
It's one week only, I think it's fine.
|
I tested your additional changes and they're working @luisherranz. Thanks! |
What?
Use
viewModulein the create-block interactivity template.Why?
Part of #57492
We should use the new
viewModulefunctionality as the preferred way for working with modules and the interactivity API.How?
We add
viewModulesupport to@wordpress/create-block.We set the
--experimental-modulesoption 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.jsonto point to the unreleased wp-scripts package (and we'll need to include another dependency):Then we can
npm iandnpm run build. We can install out plugin in a local WordPress installation or inspect the build output:build/block.jsonIf we test using a local WordPress install running the latest
trunkversion of Gutenberg, note that we won't hit this condition. We should be sure to setGUTENBERG_VERSIONin 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.phpto be sure we hit the condition and confirm the block still works as expected: