PHP-only blocks: Auto-register blocks with block API version 3 by default#72047
PHP-only blocks: Auto-register blocks with block API version 3 by default#72047
Conversation
f2227aa to
89a450d
Compare
|
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. |
|
Size Change: +42 B (0%) Total Size: 1.95 MB
ℹ️ View Unchanged
|
packages/block-library/src/index.js
Outdated
| const { name, apiVersion } = blockData; | ||
| registerBlockType( name, { | ||
| title: name, | ||
| apiVersion, |
There was a problem hiding this comment.
why can't we just set it to v3 here , instead of changing the __unstableAutoRegisterBlocks variable?
There was a problem hiding this comment.
We can if you think that's better; I just thought to pass it already bumped to 3.
There was a problem hiding this comment.
However, if the consumer explicitly defines the apiVersion other than 3 on the server side, the apiVersion on the client side and server side will not match, right? What do you think about this?
There was a problem hiding this comment.
It's the same as setting it always to 3 on the client. If it's a concern, then we shouldn't modify at all whatever got passed to the server's register_block_type.
There was a problem hiding this comment.
In 8e96635, I've changed it to check the apiVersion from the bootstrapped block type (not the registry, as correctly pointed out) before bumping it to 3.
|
Flaky tests detected in c917886. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18222462709
|
What?
Follow-up to #71794, sets the default block API version of PHP-only auto-registered blocks to 3.
Why?
Since PHP-only blocks are a new thing, it doesn't make sense to allow this registration method to register new blocks with older api versions, especially since they can throw console warnings (see #70783)
How?
apiVersionto 3.api_versionis set during the PHP registration, it would have defaulted to 1, so with this, we are basically makingapi_versionoptional during the PHP registration.Testing Instructions
api_versionset, or set it to one:apiVersionwithwp.data.select('core/blocks').getBlockTypes().find(b => b.name === 'my-plugin/php-only-test-block').apiVersion, it should be set to3.