-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Blocks: Display browser console warnings for blocks with apiVersion below 2 #70783
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
Conversation
Size Change: +3 B (0%) Total Size: 1.91 MB
ℹ️ View Unchanged
|
921a9e3
to
8d91750
Compare
One concern is that if the |
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 If 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. |
if ( settings.apiVersion <= 2 ) { | ||
warning( | ||
'Block API version is less than 2. This means that the post editor may be rendered outside the iframe. Since all editors are planned to work as iframes in the future, set the `apiVersion` field to 3 and test the block inside the iframe editor. See: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-api-versions/#version-3-wordpress-6-3' | ||
); |
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 warning should say exactly which block is being registered. There can be easily hundreds of registered blocks, how do I find which is the bad one?
Also, be prepared there will be a lot of warnings once this is active 🙂 I was playing with apiVersion
some time ago and noticed that there are many 3rd party blocks that don't declare apiVersion
at all, and it defaults to 1.
If we could make API version 3 the default, we wouldn't need this mock 🤔 See #70750 (comment) |
I think making API version 3 the default might count as a breaking change, since it might break plugins that aren't compatible with iframed editors. |
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.
We should have done this a long time ago. Thanks Aki.
I do think we should make it default as well. |
I believe this was discussed here also but it would be a breaking change since there are many blocks out there that don't specify an |
yes, maybe something that should happen later after this log is out there. Should we clarify that in the logged message too? |
We may be able to migrate in stages. Since the default API version for blocks without an explicitly defined apiVersion became 1 by #70750, many developers will see browser warnings in WP 6.9 once this PR is merged. We might be able to push the default API version to 3 in WP 7.0, taking into account developer feedback we'll get on WP 6.9. P.S. As a follow-up, I plan to disallow anything other than 3 in the block.json schema, just like theme.json. |
Flaky tests detected in 57f5487. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/16719990172
|
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, @t-hamano!
I think this looks good to merge. It would be nice to improve and place the migration guide in the block editor handbook, instead of linking to the make post, but that can be done in follow-up.
@Mamaduka Thanks for the review!
I agree. I've added it as one of the tasks on the list at the bottom here: #70743 (comment) |
See #70743 (comment)
What?
If the API version of the block being registered is below 2, a browser warning error will be displayed.
Why?
The Block API version is referenced as a factor in determining whether the Post Editor should run as an iframe or not. We plan to move the Post Editor completely to an iframe in the future, so we need to encourage developers to test their products with the iframe editor.
How?
More developer-friendly log messages or documentation are welcome!
Why?
The API version of the block below 2 is one of the factors that prevents the post editor from working as an iframe. Let's encourage developers to change their API version to 3 and test their custom blocks in the iframe editor.
Testing Instructions
Run the following code via your browser console and check the displayed message.
Also check out the linked documentation: https://github.com/WordPress/gutenberg/blob/warning-block-api-version/docs/reference-guides/block-api/block-api-versions.md#version-3--wordpress-63
Testing Instructions for Keyboard
Screenshots or screencast