Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/reference-guides/block-api/block-api-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This document lists the changes made between the different API versions.

## Version 3 (>= WordPress 6.3)
- The post editor will be iframed if all registered blocks have a Block API version 3 or higher. Adding version 3 support means that the block should work inside an iframe, though the block may still be rendered outside the iframe if not all blocks support version 3.
- See [this article](https://make.wordpress.org/core/2021/06/29/blocks-in-an-iframed-template-editor/) for a migration guide to bump the API version to 3 and make them work in an iframe editor.

## Version 2 (>= WordPress 5.6)

Expand Down
8 changes: 8 additions & 0 deletions packages/blocks/src/store/process-block-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ export const processBlockType =
null
);

if ( settings.apiVersion <= 2 ) {
warning(
`The block "${ name }" is registered with API version 2 or lower. This means that the post editor may work as a non-iframe editor.\n` +
`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.\n` +
`See: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-api-versions/#version-3-wordpress-6-3`
);
Copy link
Member

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 (
settings.description &&
typeof settings.description !== 'string'
Expand Down
34 changes: 34 additions & 0 deletions test/unit/config/suppress-browser-warnings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Suppress specific browser warnings for unit tests
*
* This file mocks the @wordpress/warning module to suppress specific
* warnings that are expected or not relevant in the test environment,
* while allowing other warnings to pass through normally.
*
* Note: This mock can be removed once the apiVersion:3 becomes the default.
*/

jest.mock( '@wordpress/warning', () => {
const mockOriginalWarning =
jest.requireActual( '@wordpress/warning' ).default;

return {
__esModule: true,
default: jest.fn( ( message ) => {
const suppressedWarningRegexes = [
/The block ".*" is registered with API version 2 or lower/, // apiVersion warnings
];
if ( typeof message === 'string' ) {
const shouldSuppress = suppressedWarningRegexes.some(
( regex ) => regex.test( message )
);
if ( shouldSuppress ) {
return;
}
}
if ( typeof mockOriginalWarning === 'function' ) {
mockOriginalWarning( message );
}
} ),
};
} );
1 change: 1 addition & 0 deletions test/unit/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
setupFiles: [
'<rootDir>/test/unit/config/global-mocks.js',
'<rootDir>/test/unit/config/gutenberg-env.js',
'<rootDir>/test/unit/config/suppress-browser-warnings.js',
],
setupFilesAfterEnv: [
'<rootDir>/test/unit/config/testing-library.js',
Expand Down
Loading