-
Notifications
You must be signed in to change notification settings - Fork 815
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
CLI Tools: update scaffolding, use block.json to register blocks. #33883
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped. Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
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.
Thanks, these changes are welcome.
I'm having some trouble running scaffolding commands locally (even on trunk
), so you may want to ask for additional testing. But everything seems good codewise.
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.
When running the script, I note the following issues:
- If you specify
--keywords
, this producesin the block.json which is not terribly helpful."keywords": [Array],
- It also doesn't properly encode the keywords, description, and such in the json, but the old version had that bug too.
- Another existing bug is that for some reason
--keywords
only accepts three keywords. If you try to do more, the output has all of them combined as the third.
@@ -0,0 +1,18 @@ | |||
{ | |||
"$schema": "https://schemas.wp.org/trunk/block.json", | |||
"apiVersion": 1, |
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.
Should new blocks be defaulting to a later api version?
For version 2, it looks like we'll also have to have the default edit
function use useBlockProps
as documented at https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/. And maybe something similar for the save
function and useBlockProps.save
.
Version 3 will probably have to wait until we're not using 'enqueue_block_editor_assets' to enqueue the monolithic editor.js though.
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.
@monsieur-z What's your take on this?
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 makes sense to nudge people to use the latest version when possible. In this case (using 2 or 3), we'd probably need to edit the save
and edit
functions in the templates to include useBlockProps();
(as in the link Brad copied) and make it visible it's required.
As for which version to use, I can't say I fully understand what using version 3 involves. The iframing might be an issue for some, but it seems it wouldn't occur unless all blocks are registered with 3 anyway.
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 I've managed to gather is that we have to make sure the scripts will be enqueued inside the iframe. Which it seems may involve somehow using the 'enqueue_block_assets' hook rather than 'enqueue_block_editor_assets', or else doing the enqueuing via block.json.
https://developer.wordpress.org/block-editor/how-to-guides/enqueueing-assets-in-the-editor/#editor-content-scripts-and-styles (and the following section) might be relevant.
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.
👍 Discussion can continue in #34120
projects/plugins/jetpack/wp-cli-templates/block-block-json.mustache
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/wp-cli-templates/block-block-json.mustache
Outdated
Show resolved
Hide resolved
Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
@anomiex Thanks for the feedback. I addressed most of it above. I had a question about
What type of encoding issue did you have in mind in this case? I tried |
Try putting Newlines might be an issue too, if someone tries a multi-line description, but I didn't try that. |
Would something like d4c48c3 help? |
Since we're dealing with json, it might be better to use actual Of course, that would mean that on the template side we'd need to not include the quotes since they're now in the source strings. Or else we'd need to do like |
Is this what you had in mind? 1f39cf3 It doesn't support new lines, but I personally think that's okay, I don't believe that is something that will be commonly passed when using the CLI command. |
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.
Yes, that's what I had in mind. Also it supported newlines fine when I tested it.
Fixes #33173
Proposed changes:
Let's update our scaffolding to encourage others to use the new nomemclature introduced in #32602.
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
jetpack docker wp -- jetpack scaffold block "Amazing Rock" --slug="good-music" --description="Rock the best music on your site" --keywords="music, audio, media, four, five"
, then build withjetpack build plugins/jetpack
, and observe the new block in the block editor.