From 6923ca3153d18d51359378448420160f8d849574 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Fri, 15 Nov 2024 10:39:22 +0400 Subject: [PATCH 1/2] Block Library: Fix React Compiler error for shortcuts --- .../src/block-keyboard-shortcuts/index.js | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/packages/block-library/src/block-keyboard-shortcuts/index.js b/packages/block-library/src/block-keyboard-shortcuts/index.js index 6d9cde8364001f..729ba99ef101d7 100644 --- a/packages/block-library/src/block-keyboard-shortcuts/index.js +++ b/packages/block-library/src/block-keyboard-shortcuts/index.js @@ -90,22 +90,36 @@ function BlockKeyboardShortcuts() { }, } ); } ); - }, [] ); + }, [ registerShortcut ] ); useShortcut( 'core/block-editor/transform-heading-to-paragraph', ( event ) => handleTransformHeadingAndParagraph( event, 0 ) ); - - [ 1, 2, 3, 4, 5, 6 ].forEach( ( level ) => { - //the loop is based off on a constant therefore - //the hook will execute the same way every time - //eslint-disable-next-line react-hooks/rules-of-hooks - useShortcut( - `core/block-editor/transform-paragraph-to-heading-${ level }`, - ( event ) => handleTransformHeadingAndParagraph( event, level ) - ); - } ); + useShortcut( + `core/block-editor/transform-paragraph-to-heading-1`, + ( event ) => handleTransformHeadingAndParagraph( event, 1 ) + ); + useShortcut( + `core/block-editor/transform-paragraph-to-heading-2`, + ( event ) => handleTransformHeadingAndParagraph( event, 2 ) + ); + useShortcut( + `core/block-editor/transform-paragraph-to-heading-3`, + ( event ) => handleTransformHeadingAndParagraph( event, 3 ) + ); + useShortcut( + `core/block-editor/transform-paragraph-to-heading-4`, + ( event ) => handleTransformHeadingAndParagraph( event, 4 ) + ); + useShortcut( + `core/block-editor/transform-paragraph-to-heading-5`, + ( event ) => handleTransformHeadingAndParagraph( event, 5 ) + ); + useShortcut( + `core/block-editor/transform-paragraph-to-heading-6`, + ( event ) => handleTransformHeadingAndParagraph( event, 6 ) + ); return null; } From 4f3d3af2aa3a43a29da6ff49373a7288f91996c0 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Fri, 15 Nov 2024 13:52:27 +0400 Subject: [PATCH 2/2] Feedback --- .../src/block-keyboard-shortcuts/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/block-library/src/block-keyboard-shortcuts/index.js b/packages/block-library/src/block-keyboard-shortcuts/index.js index 729ba99ef101d7..2ce106b8ed99dc 100644 --- a/packages/block-library/src/block-keyboard-shortcuts/index.js +++ b/packages/block-library/src/block-keyboard-shortcuts/index.js @@ -97,27 +97,27 @@ function BlockKeyboardShortcuts() { ( event ) => handleTransformHeadingAndParagraph( event, 0 ) ); useShortcut( - `core/block-editor/transform-paragraph-to-heading-1`, + 'core/block-editor/transform-paragraph-to-heading-1', ( event ) => handleTransformHeadingAndParagraph( event, 1 ) ); useShortcut( - `core/block-editor/transform-paragraph-to-heading-2`, + 'core/block-editor/transform-paragraph-to-heading-2', ( event ) => handleTransformHeadingAndParagraph( event, 2 ) ); useShortcut( - `core/block-editor/transform-paragraph-to-heading-3`, + 'core/block-editor/transform-paragraph-to-heading-3', ( event ) => handleTransformHeadingAndParagraph( event, 3 ) ); useShortcut( - `core/block-editor/transform-paragraph-to-heading-4`, + 'core/block-editor/transform-paragraph-to-heading-4', ( event ) => handleTransformHeadingAndParagraph( event, 4 ) ); useShortcut( - `core/block-editor/transform-paragraph-to-heading-5`, + 'core/block-editor/transform-paragraph-to-heading-5', ( event ) => handleTransformHeadingAndParagraph( event, 5 ) ); useShortcut( - `core/block-editor/transform-paragraph-to-heading-6`, + 'core/block-editor/transform-paragraph-to-heading-6', ( event ) => handleTransformHeadingAndParagraph( event, 6 ) );