-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Changes from all commits
8d91750
1aba967
2ff5748
5200910
a661bcf
3e1e1d2
57f5487
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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` | ||
| ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
|
|
||
| if ( | ||
| settings.description && | ||
| typeof settings.description !== 'string' | ||
|
|
||
| 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 ); | ||
| } | ||
| } ), | ||
| }; | ||
| } ); |
Uh oh!
There was an error while loading. Please reload this page.