From 4369ec0f999dbd33d599a0d5d43f01df5a603cf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:26:21 +0200 Subject: [PATCH] Add back test and warning about parent as a string --- packages/blocks/src/api/test/registration.js | 10 ++++++++-- packages/blocks/src/store/process-block-type.js | 14 ++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/blocks/src/api/test/registration.js b/packages/blocks/src/api/test/registration.js index 7db5cc7a65c8a..5941415e61fe5 100644 --- a/packages/blocks/src/api/test/registration.js +++ b/packages/blocks/src/api/test/registration.js @@ -749,8 +749,14 @@ describe( 'blocks', () => { title: 'block title', parent: 'core/paragraph', }; - registerBlockType( 'core/test-block-parent-string', blockType ); - expect( getBlockType( 'core/test-block-parent-string' ) ).toEqual( { + const block = registerBlockType( + 'core/test-block-parent-string', + blockType + ); + expect( console ).toHaveWarnedWith( + 'Parent must be undefined or an array of strings (block types), but it is a string.' + ); + expect( block ).toEqual( { name: 'core/test-block-parent-string', save: noop, category: 'text', diff --git a/packages/blocks/src/store/process-block-type.js b/packages/blocks/src/store/process-block-type.js index 63bef081a6b5d..bc7b1a0e10e77 100644 --- a/packages/blocks/src/store/process-block-type.js +++ b/packages/blocks/src/store/process-block-type.js @@ -197,14 +197,20 @@ export const processBlockType = return; } - // Parent being an array hasn't been enforced in the past, - // so this is a way to maintain backwards compatibility - // with 3rd party blocks that may have been using it as a string. if ( typeof settings?.parent === 'string' || settings?.parent instanceof String ) { settings.parent = [ settings.parent ]; + warning( + 'Parent must be undefined or an array of strings (block types), but it is a string.' + ); + // Intentionally continue: + // + // While string values were never supported, they appeared to work with some unintended side-effects + // that have been fixed by [#66250](https://github.com/WordPress/gutenberg/pull/66250). + // + // To be backwards-compatible, this code that automatically migrates strings to arrays. } if ( @@ -212,7 +218,7 @@ export const processBlockType = settings?.parent !== undefined ) { warning( - 'Block parent must be undefined or an array of block types, but it is ', + 'Parent must be undefined or an array of block types, but it is ', settings.parent ); return;