From ab4b075110df943a4da54ea9023dd49a9d2050ed Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Tue, 4 Jun 2024 13:01:00 -0400 Subject: [PATCH 01/44] Add Post_Types_Controller compat class. Add rendering_mode parameter to API response. --- ...tenberg-rest-post-types-controller-6-6.php | 40 +++++++++++++++++++ lib/compat/wordpress-6.6/rest-api.php | 10 +++++ lib/load.php | 1 + 3 files changed, 51 insertions(+) create mode 100644 lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php diff --git a/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php b/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php new file mode 100644 index 0000000000000..e4951aeba7c29 --- /dev/null +++ b/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php @@ -0,0 +1,40 @@ +data['rendering_mode'] = apply_filters( 'post_type_default_rendering_mode', 'post-only', $item->name ); + } + + return $response; + } +} diff --git a/lib/compat/wordpress-6.6/rest-api.php b/lib/compat/wordpress-6.6/rest-api.php index 2cf026cc817c1..47b09f5191a73 100644 --- a/lib/compat/wordpress-6.6/rest-api.php +++ b/lib/compat/wordpress-6.6/rest-api.php @@ -77,6 +77,16 @@ function gutenberg_add_class_list_to_public_post_types() { } add_action( 'rest_api_init', 'gutenberg_add_class_list_to_public_post_types' ); +if ( ! function_exists( 'gutenberg_add_post_type_rendering_mode' ) ) { + /** + * Add Block Editor default rendering mode to the post type response. + */ + function gutenberg_add_post_type_rendering_mode() { + $controller = new Gutenberg_REST_Post_Types_Controller_6_6(); + $controller->register_routes(); + } +} +add_action( 'rest_api_init', 'gutenberg_add_post_type_rendering_mode' ); /** * Registers the Global Styles Revisions REST API routes. diff --git a/lib/load.php b/lib/load.php index 1f63c816f8173..cc57b55fb7dd6 100644 --- a/lib/load.php +++ b/lib/load.php @@ -49,6 +49,7 @@ function gutenberg_is_experiment_enabled( $name ) { // WordPress 6.6 compat. require __DIR__ . '/compat/wordpress-6.6/class-gutenberg-rest-global-styles-revisions-controller-6-6.php'; require __DIR__ . '/compat/wordpress-6.6/class-gutenberg-rest-templates-controller-6-6.php'; + require __DIR__ . '/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php'; require __DIR__ . '/compat/wordpress-6.6/rest-api.php'; // Plugin specific code. From ca0de5dfda8802e91a7bc111e26b80081bce432d Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Tue, 4 Jun 2024 14:32:21 -0400 Subject: [PATCH 02/44] Add the rendering_mode property to the post type object properties --- ...tenberg-rest-post-types-controller-6-6.php | 18 ++++++++++++++--- lib/compat/wordpress-6.6/post.php | 20 ++++++++++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php b/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php index e4951aeba7c29..8f3d0c4485359 100644 --- a/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php +++ b/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php @@ -23,7 +23,19 @@ public function prepare_item_for_response( $item, $request ) { $response = parent::prepare_item_for_response( $item, $request ); $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; - if ( 'edit' === $context ) { + if ( 'edit' === $context && post_type_supports( $item->name, 'editor' ) ) { + /** + * Filters the block editor rendering mode for a specific post type. + * + * The dynamic portion of the hook name, `$item->name`, refers to the post type slug. + * + * @since 6.6.0 + * @param string $default_rendering_mode Default rendering mode for the post type. + * @param string $post_type Post type name. + * @return string Default rendering mode for the post type. + */ + $response->data['rendering_mode'] = apply_filters( "{$item->name}_default_rendering_mode", $item->rendering_mode, $item->name ); + /** * Filters the block editor rendering mode for a post type. * @@ -32,9 +44,9 @@ public function prepare_item_for_response( $item, $request ) { * @param string $post_type Post type name. * @return string Default rendering mode for the post type. */ - $response->data['rendering_mode'] = apply_filters( 'post_type_default_rendering_mode', 'post-only', $item->name ); + $response->data['rendering_mode'] = apply_filters( 'post_type_default_rendering_mode', $item->rendering_mode, $item->name ); } - return $response; + return rest_ensure_response( $response ); } } diff --git a/lib/compat/wordpress-6.6/post.php b/lib/compat/wordpress-6.6/post.php index 8415f3bf42f18..35b0aedba653c 100644 --- a/lib/compat/wordpress-6.6/post.php +++ b/lib/compat/wordpress-6.6/post.php @@ -11,9 +11,27 @@ function gutenberg_add_excerpt_support_to_wp_block() { add_post_type_support( 'wp_block', 'excerpt' ); } - add_action( 'init', 'gutenberg_add_excerpt_support_to_wp_block' ); +/** + * Add the rendering_mode property to the WP_Post_Type object. + * This property can be overwritten by using the post_type_default_rendering_mode filter. + * + * @param array $args Array of post type arguments. + * @return array Updated array of post type arguments. + */ +function gutenberg_post_type_default_rendering_mode( $args ) { + if ( + ( isset( $args['show_in_rest'] ) && $args['show_in_rest'] ) && + ( isset( $args['supports'] ) && in_array( 'editor', $args['supports'], true ) ) + ) { + $args['rendering_mode'] = 'post-only'; + } + + return $args; +} +add_filter( 'register_post_type_args', 'gutenberg_post_type_default_rendering_mode', 10, 2 ); + /** * Updates the labels for the template post type. * From 3beef1ee9e650d2efc6719dff8ae2cd3faccdc97 Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Tue, 4 Jun 2024 14:39:13 -0400 Subject: [PATCH 03/44] Check that the rendering_mode property exists before attempting to access. --- .../class-gutenberg-rest-post-types-controller-6-6.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php b/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php index 8f3d0c4485359..b2d2ee184eb75 100644 --- a/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php +++ b/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php @@ -23,7 +23,8 @@ public function prepare_item_for_response( $item, $request ) { $response = parent::prepare_item_for_response( $item, $request ); $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; - if ( 'edit' === $context && post_type_supports( $item->name, 'editor' ) ) { + // Property will only exist if the post type supports the block editor. + if ( 'edit' === $context && property_exists( $item, 'rendering_mode' ) ) { /** * Filters the block editor rendering mode for a specific post type. * From 9b276d2b3aaced1cbfc6782c5cec2197a8ea5e6a Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Tue, 4 Jun 2024 15:19:45 -0400 Subject: [PATCH 04/44] Fix PHP filters from overriding one another. Implement the defaultRenderingMode value into the Editor rendering function. --- ...utenberg-rest-post-types-controller-6-6.php | 8 ++++---- lib/compat/wordpress-6.6/post.php | 4 ++-- packages/edit-post/src/editor.js | 18 ++++++++++++++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php b/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php index b2d2ee184eb75..b871e411f5074 100644 --- a/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php +++ b/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php @@ -31,11 +31,11 @@ public function prepare_item_for_response( $item, $request ) { * The dynamic portion of the hook name, `$item->name`, refers to the post type slug. * * @since 6.6.0 - * @param string $default_rendering_mode Default rendering mode for the post type. - * @param string $post_type Post type name. + * @param string $default_rendering_mode Default rendering mode for the post type. + * @param WP_Post_Type $post_type Post type object. * @return string Default rendering mode for the post type. */ - $response->data['rendering_mode'] = apply_filters( "{$item->name}_default_rendering_mode", $item->rendering_mode, $item->name ); + $rendering_mode = apply_filters( "{$item->name}_default_rendering_mode", $item->rendering_mode, $item ); /** * Filters the block editor rendering mode for a post type. @@ -45,7 +45,7 @@ public function prepare_item_for_response( $item, $request ) { * @param string $post_type Post type name. * @return string Default rendering mode for the post type. */ - $response->data['rendering_mode'] = apply_filters( 'post_type_default_rendering_mode', $item->rendering_mode, $item->name ); + $response->data['rendering_mode'] = apply_filters( 'post_type_default_rendering_mode', $rendering_mode, $item->name ); } return rest_ensure_response( $response ); diff --git a/lib/compat/wordpress-6.6/post.php b/lib/compat/wordpress-6.6/post.php index 35b0aedba653c..f7538675bf097 100644 --- a/lib/compat/wordpress-6.6/post.php +++ b/lib/compat/wordpress-6.6/post.php @@ -17,7 +17,7 @@ function gutenberg_add_excerpt_support_to_wp_block() { * Add the rendering_mode property to the WP_Post_Type object. * This property can be overwritten by using the post_type_default_rendering_mode filter. * - * @param array $args Array of post type arguments. + * @param array $args Array of post type arguments. * @return array Updated array of post type arguments. */ function gutenberg_post_type_default_rendering_mode( $args ) { @@ -30,7 +30,7 @@ function gutenberg_post_type_default_rendering_mode( $args ) { return $args; } -add_filter( 'register_post_type_args', 'gutenberg_post_type_default_rendering_mode', 10, 2 ); +add_filter( 'register_post_type_args', 'gutenberg_post_type_default_rendering_mode', 10, 1 ); /** * Updates the labels for the template post type. diff --git a/packages/edit-post/src/editor.js b/packages/edit-post/src/editor.js index 378265c192778..3a09c90a2f2e7 100644 --- a/packages/edit-post/src/editor.js +++ b/packages/edit-post/src/editor.js @@ -31,6 +31,20 @@ function Editor( { initialEdits, ...props } ) { + // Get the rendering mode for the post type. + const postTypeRenderingMode = useSelect( + ( select ) => { + const postTypeObject = + select( coreStore ).getPostType( initialPostType ); + if ( postTypeObject && postTypeObject?.rendering_mode ) { + return postTypeObject?.rendering_mode; + } + + return 'post-only'; + }, + [ initialPostType ] + ); + const { currentPost, onNavigateToEntityRecord, @@ -38,7 +52,7 @@ function Editor( { } = useNavigateToEntityRecord( initialPostId, initialPostType, - 'post-only' + postTypeRenderingMode ); const { post, template } = useSelect( @@ -78,7 +92,7 @@ function Editor( { ...settings, onNavigateToEntityRecord, onNavigateToPreviousEntityRecord, - defaultRenderingMode: 'post-only', + defaultRenderingMode: postTypeRenderingMode, } ), [ settings, onNavigateToEntityRecord, onNavigateToPreviousEntityRecord ] ); From a26a583f47419476d64cce7363d39c68794fef11 Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Tue, 4 Jun 2024 15:29:45 -0400 Subject: [PATCH 05/44] Remove unnecessary optional chain inside conditional --- packages/edit-post/src/editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/edit-post/src/editor.js b/packages/edit-post/src/editor.js index 3a09c90a2f2e7..55d9b500de267 100644 --- a/packages/edit-post/src/editor.js +++ b/packages/edit-post/src/editor.js @@ -37,7 +37,7 @@ function Editor( { const postTypeObject = select( coreStore ).getPostType( initialPostType ); if ( postTypeObject && postTypeObject?.rendering_mode ) { - return postTypeObject?.rendering_mode; + return postTypeObject.rendering_mode; } return 'post-only'; From b538ae67dc2ddb681db069aa7bbe9cee024ee770 Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Tue, 4 Jun 2024 15:37:08 -0400 Subject: [PATCH 06/44] Dont override the rendering_mode value if set during post type registration. --- lib/compat/wordpress-6.6/post.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.6/post.php b/lib/compat/wordpress-6.6/post.php index f7538675bf097..2abcd608cb3f4 100644 --- a/lib/compat/wordpress-6.6/post.php +++ b/lib/compat/wordpress-6.6/post.php @@ -23,7 +23,8 @@ function gutenberg_add_excerpt_support_to_wp_block() { function gutenberg_post_type_default_rendering_mode( $args ) { if ( ( isset( $args['show_in_rest'] ) && $args['show_in_rest'] ) && - ( isset( $args['supports'] ) && in_array( 'editor', $args['supports'], true ) ) + ( isset( $args['supports'] ) && in_array( 'editor', $args['supports'], true ) ) && + ( ! isset( $args['rendering_mode'] ) ) ) { $args['rendering_mode'] = 'post-only'; } From e3912d49933da11470e7c4198f15b8e1902f9817 Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Wed, 5 Jun 2024 10:19:21 -0400 Subject: [PATCH 07/44] Move all code to a new 6.7 compat directory. Update the post type property to read default_rendering_mode. --- lib/compat/wordpress-6.6/post.php | 20 -------------- lib/compat/wordpress-6.6/rest-api.php | 11 -------- ...enberg-rest-post-types-controller-6-7.php} | 12 ++++----- lib/compat/wordpress-6.7/post.php | 26 +++++++++++++++++++ lib/compat/wordpress-6.7/rest-api.php | 22 ++++++++++++++++ lib/load.php | 8 +++++- packages/edit-post/src/editor.js | 4 +-- 7 files changed, 63 insertions(+), 40 deletions(-) rename lib/compat/{wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php => wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php} (78%) create mode 100644 lib/compat/wordpress-6.7/post.php create mode 100644 lib/compat/wordpress-6.7/rest-api.php diff --git a/lib/compat/wordpress-6.6/post.php b/lib/compat/wordpress-6.6/post.php index 2abcd608cb3f4..857ac6fc7d9ed 100644 --- a/lib/compat/wordpress-6.6/post.php +++ b/lib/compat/wordpress-6.6/post.php @@ -13,26 +13,6 @@ function gutenberg_add_excerpt_support_to_wp_block() { } add_action( 'init', 'gutenberg_add_excerpt_support_to_wp_block' ); -/** - * Add the rendering_mode property to the WP_Post_Type object. - * This property can be overwritten by using the post_type_default_rendering_mode filter. - * - * @param array $args Array of post type arguments. - * @return array Updated array of post type arguments. - */ -function gutenberg_post_type_default_rendering_mode( $args ) { - if ( - ( isset( $args['show_in_rest'] ) && $args['show_in_rest'] ) && - ( isset( $args['supports'] ) && in_array( 'editor', $args['supports'], true ) ) && - ( ! isset( $args['rendering_mode'] ) ) - ) { - $args['rendering_mode'] = 'post-only'; - } - - return $args; -} -add_filter( 'register_post_type_args', 'gutenberg_post_type_default_rendering_mode', 10, 1 ); - /** * Updates the labels for the template post type. * diff --git a/lib/compat/wordpress-6.6/rest-api.php b/lib/compat/wordpress-6.6/rest-api.php index 47b09f5191a73..1f791570f09c7 100644 --- a/lib/compat/wordpress-6.6/rest-api.php +++ b/lib/compat/wordpress-6.6/rest-api.php @@ -77,17 +77,6 @@ function gutenberg_add_class_list_to_public_post_types() { } add_action( 'rest_api_init', 'gutenberg_add_class_list_to_public_post_types' ); -if ( ! function_exists( 'gutenberg_add_post_type_rendering_mode' ) ) { - /** - * Add Block Editor default rendering mode to the post type response. - */ - function gutenberg_add_post_type_rendering_mode() { - $controller = new Gutenberg_REST_Post_Types_Controller_6_6(); - $controller->register_routes(); - } -} -add_action( 'rest_api_init', 'gutenberg_add_post_type_rendering_mode' ); - /** * Registers the Global Styles Revisions REST API routes. */ diff --git a/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php b/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php similarity index 78% rename from lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php rename to lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php index b871e411f5074..de5b594986930 100644 --- a/lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php +++ b/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php @@ -1,17 +1,17 @@ name}_default_rendering_mode", $item->rendering_mode, $item ); + $rendering_mode = apply_filters( "{$item->name}_default_rendering_mode", $item->default_rendering_mode, $item ); /** * Filters the block editor rendering mode for a post type. @@ -45,7 +45,7 @@ public function prepare_item_for_response( $item, $request ) { * @param string $post_type Post type name. * @return string Default rendering mode for the post type. */ - $response->data['rendering_mode'] = apply_filters( 'post_type_default_rendering_mode', $rendering_mode, $item->name ); + $response->data['default_rendering_mode'] = apply_filters( 'post_type_default_rendering_mode', $rendering_mode, $item->name ); } return rest_ensure_response( $response ); diff --git a/lib/compat/wordpress-6.7/post.php b/lib/compat/wordpress-6.7/post.php new file mode 100644 index 0000000000000..4c12422d14dcd --- /dev/null +++ b/lib/compat/wordpress-6.7/post.php @@ -0,0 +1,26 @@ +register_routes(); + } +} +add_action( 'rest_api_init', 'gutenberg_add_post_type_rendering_mode' ); diff --git a/lib/load.php b/lib/load.php index cc57b55fb7dd6..6224d8ffc1f28 100644 --- a/lib/load.php +++ b/lib/load.php @@ -49,9 +49,12 @@ function gutenberg_is_experiment_enabled( $name ) { // WordPress 6.6 compat. require __DIR__ . '/compat/wordpress-6.6/class-gutenberg-rest-global-styles-revisions-controller-6-6.php'; require __DIR__ . '/compat/wordpress-6.6/class-gutenberg-rest-templates-controller-6-6.php'; - require __DIR__ . '/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php'; require __DIR__ . '/compat/wordpress-6.6/rest-api.php'; + // WordPress 6.7 compat. + require __DIR__ . '/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php'; + require __DIR__ . '/compat/wordpress-6.7/rest-api.php'; + // Plugin specific code. require_once __DIR__ . '/class-wp-rest-global-styles-controller-gutenberg.php'; require_once __DIR__ . '/class-wp-rest-edit-site-export-controller-gutenberg.php'; @@ -141,6 +144,9 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-6.6/option.php'; require __DIR__ . '/compat/wordpress-6.6/post.php'; +// WordPress 6.7 compat. +require __DIR__ . '/compat/wordpress-6.7/post.php'; + // Experimental features. require __DIR__ . '/experimental/block-editor-settings-mobile.php'; require __DIR__ . '/experimental/blocks.php'; diff --git a/packages/edit-post/src/editor.js b/packages/edit-post/src/editor.js index 55d9b500de267..2252b143d3ecc 100644 --- a/packages/edit-post/src/editor.js +++ b/packages/edit-post/src/editor.js @@ -36,8 +36,8 @@ function Editor( { ( select ) => { const postTypeObject = select( coreStore ).getPostType( initialPostType ); - if ( postTypeObject && postTypeObject?.rendering_mode ) { - return postTypeObject.rendering_mode; + if ( postTypeObject && postTypeObject?.default_rendering_mode ) { + return postTypeObject.default_rendering_mode; } return 'post-only'; From 702a5be1037513f389e0aa2cf475b70810df0ed9 Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Thu, 6 Jun 2024 12:53:29 -0400 Subject: [PATCH 08/44] Update rendering_mode filters to always be prefixed with post_type_ --- .../class-gutenberg-rest-post-types-controller-6-7.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php b/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php index de5b594986930..a77de11442d80 100644 --- a/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php +++ b/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php @@ -35,17 +35,17 @@ public function prepare_item_for_response( $item, $request ) { * @param WP_Post_Type $post_type Post type object. * @return string Default rendering mode for the post type. */ - $rendering_mode = apply_filters( "{$item->name}_default_rendering_mode", $item->default_rendering_mode, $item ); + $rendering_mode = apply_filters( "post_type_{$item->name}_default_rendering_mode", $item->default_rendering_mode, $item ); /** * Filters the block editor rendering mode for a post type. * * @since 6.6.0 - * @param string $default_rendering_mode Default rendering mode for the post type. - * @param string $post_type Post type name. + * @param string $default_rendering_mode Default rendering mode for the post type. + * @param WP_Post_Type $post_type Post type name. * @return string Default rendering mode for the post type. */ - $response->data['default_rendering_mode'] = apply_filters( 'post_type_default_rendering_mode', $rendering_mode, $item->name ); + $response->data['default_rendering_mode'] = apply_filters( 'post_type_default_rendering_mode', $rendering_mode, $item ); } return rest_ensure_response( $response ); From 964a14845ea2bf169acd688ceb9ffaf66b81ccee Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Thu, 6 Jun 2024 13:41:20 -0400 Subject: [PATCH 09/44] Remove the editor mode props from the individual editors (site + post). Add the post type editor mode logic to the root editor package and save in store. --- packages/edit-post/src/editor.js | 21 +------- .../block-editor/use-site-editor-settings.js | 53 ++++++++----------- .../editor/src/components/provider/index.js | 33 +++++++++--- 3 files changed, 49 insertions(+), 58 deletions(-) diff --git a/packages/edit-post/src/editor.js b/packages/edit-post/src/editor.js index 2252b143d3ecc..6b5bd0c340b06 100644 --- a/packages/edit-post/src/editor.js +++ b/packages/edit-post/src/editor.js @@ -31,29 +31,11 @@ function Editor( { initialEdits, ...props } ) { - // Get the rendering mode for the post type. - const postTypeRenderingMode = useSelect( - ( select ) => { - const postTypeObject = - select( coreStore ).getPostType( initialPostType ); - if ( postTypeObject && postTypeObject?.default_rendering_mode ) { - return postTypeObject.default_rendering_mode; - } - - return 'post-only'; - }, - [ initialPostType ] - ); - const { currentPost, onNavigateToEntityRecord, onNavigateToPreviousEntityRecord, - } = useNavigateToEntityRecord( - initialPostId, - initialPostType, - postTypeRenderingMode - ); + } = useNavigateToEntityRecord( initialPostId, initialPostType ); const { post, template } = useSelect( ( select ) => { @@ -92,7 +74,6 @@ function Editor( { ...settings, onNavigateToEntityRecord, onNavigateToPreviousEntityRecord, - defaultRenderingMode: postTypeRenderingMode, } ), [ settings, onNavigateToEntityRecord, onNavigateToPreviousEntityRecord ] ); diff --git a/packages/edit-site/src/components/block-editor/use-site-editor-settings.js b/packages/edit-site/src/components/block-editor/use-site-editor-settings.js index 8e02f06d37edf..48acd8016978c 100644 --- a/packages/edit-site/src/components/block-editor/use-site-editor-settings.js +++ b/packages/edit-site/src/components/block-editor/use-site-editor-settings.js @@ -114,37 +114,28 @@ function useNavigateToPreviousEntityRecord() { export function useSpecificEditorSettings() { const onNavigateToEntityRecord = useNavigateToEntityRecord(); - const { templateSlug, canvasMode, settings, postWithTemplate } = useSelect( - ( select ) => { - const { - getEditedPostType, - getEditedPostId, - getEditedPostContext, - getCanvasMode, - getSettings, - } = unlock( select( editSiteStore ) ); - const { getEditedEntityRecord } = select( coreStore ); - const usedPostType = getEditedPostType(); - const usedPostId = getEditedPostId(); - const _record = getEditedEntityRecord( - 'postType', - usedPostType, - usedPostId - ); - const _context = getEditedPostContext(); - return { - templateSlug: _record.slug, - canvasMode: getCanvasMode(), - settings: getSettings(), - postWithTemplate: _context?.postId, - }; - }, - [] - ); + const { templateSlug, canvasMode, settings } = useSelect( ( select ) => { + const { + getEditedPostType, + getEditedPostId, + getCanvasMode, + getSettings, + } = unlock( select( editSiteStore ) ); + const { getEditedEntityRecord } = select( coreStore ); + const usedPostType = getEditedPostType(); + const usedPostId = getEditedPostId(); + const _record = getEditedEntityRecord( + 'postType', + usedPostType, + usedPostId + ); + return { + templateSlug: _record.slug, + canvasMode: getCanvasMode(), + settings: getSettings(), + }; + }, [] ); const archiveLabels = useArchiveLabel( templateSlug ); - const defaultRenderingMode = postWithTemplate - ? 'template-locked' - : 'post-only'; const onNavigateToPreviousEntityRecord = useNavigateToPreviousEntityRecord(); const defaultEditorSettings = useMemo( () => { @@ -154,7 +145,6 @@ export function useSpecificEditorSettings() { richEditingEnabled: true, supportsTemplateMode: true, focusMode: canvasMode !== 'view', - defaultRenderingMode, onNavigateToEntityRecord, onNavigateToPreviousEntityRecord, // I wonder if they should be set in the post editor too @@ -165,7 +155,6 @@ export function useSpecificEditorSettings() { }, [ settings, canvasMode, - defaultRenderingMode, onNavigateToEntityRecord, onNavigateToPreviousEntityRecord, archiveLabels.archiveTypeLabel, diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index 081b1cdfa0f1b..6834dc4046544 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -4,7 +4,11 @@ import { useEffect, useLayoutEffect, useMemo } from '@wordpress/element'; import { useDispatch, useSelect } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; -import { EntityProvider, useEntityBlockEditor } from '@wordpress/core-data'; +import { + EntityProvider, + useEntityBlockEditor, + store as coreStore, +} from '@wordpress/core-data'; import { BlockEditorProvider, BlockContextProvider, @@ -161,8 +165,17 @@ export const ExperimentalEditorProvider = withRegistryProvider( __unstableTemplate: template, } ) => { const mode = useSelect( - ( select ) => select( editorStore ).getRenderingMode(), - [] + ( select ) => { + const postTypeObject = select( coreStore ).getPostType( + post.type + ); + return ( + postTypeObject?.default_rendering_mode ?? + settings.defaultRenderingMode ?? + 'post-only' + ); + }, + [ post, coreStore, settings ] ); const shouldRenderTemplate = !! template && mode !== 'post-only'; const rootLevelPost = shouldRenderTemplate ? template : post; @@ -250,7 +263,15 @@ export const ExperimentalEditorProvider = withRegistryProvider( } ); } - }, [] ); + }, [ + createWarningNotice, + initialEdits, + settings, + post, + recovery, + setupEditor, + updatePostLock, + ] ); // Synchronizes the active post with the state useEffect( () => { @@ -269,8 +290,8 @@ export const ExperimentalEditorProvider = withRegistryProvider( // Sets the right rendering mode when loading the editor. useEffect( () => { - setRenderingMode( settings.defaultRenderingMode ?? 'post-only' ); - }, [ settings.defaultRenderingMode, setRenderingMode ] ); + setRenderingMode( mode ); + }, [ mode ] ); useHideBlocksFromInserter( post.type, mode ); From 298c858dc5188b06765db8dafd12550f6b06e54a Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Mon, 10 Jun 2024 10:29:40 -0400 Subject: [PATCH 10/44] Prevent rendering editor until mode constant is defined. --- packages/editor/src/components/provider/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index c8ab31971a54e..d6a5a2dc3cf4b 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -300,7 +300,7 @@ export const ExperimentalEditorProvider = withRegistryProvider( // Register the editor commands. useCommands(); - if ( ! isReady ) { + if ( ! isReady || ! mode ) { return null; } From d85f56c151e9ad39423bd1bf523ece576a457c0e Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Mon, 10 Jun 2024 10:42:32 -0400 Subject: [PATCH 11/44] Add validation for rendering modes passed to post types. --- ...tenberg-rest-post-types-controller-6-7.php | 9 ++++- lib/compat/wordpress-6.7/post.php | 36 +++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php b/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php index a77de11442d80..9df292b0f9446 100644 --- a/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php +++ b/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php @@ -45,7 +45,14 @@ public function prepare_item_for_response( $item, $request ) { * @param WP_Post_Type $post_type Post type name. * @return string Default rendering mode for the post type. */ - $response->data['default_rendering_mode'] = apply_filters( 'post_type_default_rendering_mode', $rendering_mode, $item ); + $rendering_mode = apply_filters( 'post_type_default_rendering_mode', $rendering_mode, $item ); + + // Validate the filtered rendering mode. + if ( ! in_array( $rendering_mode, gutenberg_rendering_modes(), true ) ) { + $rendering_mode = 'post-only'; + } + + $response->data['default_rendering_mode'] = $rendering_mode; } return rest_ensure_response( $response ); diff --git a/lib/compat/wordpress-6.7/post.php b/lib/compat/wordpress-6.7/post.php index 4c12422d14dcd..f5e37dd25277e 100644 --- a/lib/compat/wordpress-6.7/post.php +++ b/lib/compat/wordpress-6.7/post.php @@ -5,6 +5,25 @@ * @package gutenberg */ +/** + * Get the available rendering modes for the Block Editor. + * + * post-only: This mode extracts the post blocks from the template and renders only those. + * The idea is to allow the user to edit the post/page in isolation without the wrapping template. + * + * template-locked: This mode renders both the template and the post blocks + * but the template blocks are locked and can't be edited. The post blocks are editable. + * + * @return array Array of available rendering modes. + */ +function gutenberg_rendering_modes() { + return [ + 'post-only', + 'template-lock', + 'template-locked', + ]; +} + /** * Add the default_rendering_mode property to the WP_Post_Type object. * This property can be overwritten by using the post_type_default_rendering_mode filter. @@ -13,12 +32,23 @@ * @return array Updated array of post type arguments. */ function gutenberg_post_type_default_rendering_mode( $args ) { + $rendering_mode = 'post-only'; + $rendering_modes = gutenberg_rendering_modes(); + + // Make sure the post type supports the block editor. if ( ( isset( $args['show_in_rest'] ) && $args['show_in_rest'] ) && - ( isset( $args['supports'] ) && in_array( 'editor', $args['supports'], true ) ) && - ( ! isset( $args['default_rendering_mode'] ) ) + ( isset( $args['supports'] ) && in_array( 'editor', $args['supports'], true ) ) ) { - $args['default_rendering_mode'] = 'post-only'; + // Validate the supplied rendering mode. + if ( + isset( $args['default_rendering_mode'] ) && + in_array( $args['default_rendering_mode'], $rendering_modes, true ) + ) { + $rendering_mode = $args['default_rendering_mode']; + } + + $args['default_rendering_mode'] = $rendering_mode; } return $args; From de00c45591363531a694129a6433275b9f986fc9 Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Tue, 11 Jun 2024 08:44:42 -0400 Subject: [PATCH 12/44] Use a single useSelect() hook --- .../editor/src/components/provider/index.js | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index d6a5a2dc3cf4b..0b4c34e4c1579 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -165,34 +165,25 @@ export const ExperimentalEditorProvider = withRegistryProvider( BlockEditorProviderComponent = ExperimentalBlockEditorProvider, __unstableTemplate: template, } ) => { - const mode = useSelect( - ( select ) => { - const postTypeObject = select( coreStore ).getPostType( - post.type - ); - return ( - postTypeObject?.default_rendering_mode ?? - settings.defaultRenderingMode ?? - 'post-only' - ); - }, - [ post, settings ] - ); - - const { editorSettings, selection, isReady } = useSelect( + const { editorSettings, selection, isReady, mode } = useSelect( ( select ) => { const { getEditorSettings, getEditorSelection, __unstableIsEditorReady, } = select( editorStore ); + + const postTypeObject = select( coreStore ).getPostType( + post.type + ); return { editorSettings: getEditorSettings(), isReady: __unstableIsEditorReady(), selection: getEditorSelection(), + mode: postTypeObject?.default_rendering_mode ?? 'post-only', }; }, - [] + [ post ] ); const shouldRenderTemplate = !! template && mode !== 'post-only'; const rootLevelPost = shouldRenderTemplate ? template : post; From bf3fbcad8b7b3c4b882caef3015f42c382e0c044 Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Tue, 11 Jun 2024 08:51:19 -0400 Subject: [PATCH 13/44] Set default rendering mode for pages to template-locked --- lib/compat/wordpress-6.7/post.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/compat/wordpress-6.7/post.php b/lib/compat/wordpress-6.7/post.php index f5e37dd25277e..945041ba0d6bf 100644 --- a/lib/compat/wordpress-6.7/post.php +++ b/lib/compat/wordpress-6.7/post.php @@ -29,10 +29,11 @@ function gutenberg_rendering_modes() { * This property can be overwritten by using the post_type_default_rendering_mode filter. * * @param array $args Array of post type arguments. + * @param string $post_type Post type key. * @return array Updated array of post type arguments. */ -function gutenberg_post_type_default_rendering_mode( $args ) { - $rendering_mode = 'post-only'; +function gutenberg_post_type_default_rendering_mode( $args, $post_type ) { + $rendering_mode = 'page' === $post_type ? 'template-locked' : 'post-only'; $rendering_modes = gutenberg_rendering_modes(); // Make sure the post type supports the block editor. @@ -53,4 +54,4 @@ function gutenberg_post_type_default_rendering_mode( $args ) { return $args; } -add_filter( 'register_post_type_args', 'gutenberg_post_type_default_rendering_mode', 10, 1 ); +add_filter( 'register_post_type_args', 'gutenberg_post_type_default_rendering_mode', 10, 2 ); From 40c2fa3a169675c8f37894d670965b922b3d43ac Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Wed, 12 Jun 2024 12:29:55 -0400 Subject: [PATCH 14/44] Use post.type as hook dependency instead of full post object --- packages/editor/src/components/provider/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index 0b4c34e4c1579..54f52873f4aad 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -183,7 +183,7 @@ export const ExperimentalEditorProvider = withRegistryProvider( mode: postTypeObject?.default_rendering_mode ?? 'post-only', }; }, - [ post ] + [ post.type ] ); const shouldRenderTemplate = !! template && mode !== 'post-only'; const rootLevelPost = shouldRenderTemplate ? template : post; From 1f7ff09bb0300500e4a46f8b58966ddb1982d6c5 Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Thu, 13 Jun 2024 11:18:10 -0400 Subject: [PATCH 15/44] Fix since documentation. Fix array standard. --- .../class-gutenberg-rest-post-types-controller-6-7.php | 4 ++-- lib/compat/wordpress-6.7/post.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php b/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php index 9df292b0f9446..6c87ef16bcaa0 100644 --- a/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php +++ b/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php @@ -30,7 +30,7 @@ public function prepare_item_for_response( $item, $request ) { * * The dynamic portion of the hook name, `$item->name`, refers to the post type slug. * - * @since 6.6.0 + * @since 6.7.0 * @param string $default_rendering_mode Default rendering mode for the post type. * @param WP_Post_Type $post_type Post type object. * @return string Default rendering mode for the post type. @@ -40,7 +40,7 @@ public function prepare_item_for_response( $item, $request ) { /** * Filters the block editor rendering mode for a post type. * - * @since 6.6.0 + * @since 6.7.0 * @param string $default_rendering_mode Default rendering mode for the post type. * @param WP_Post_Type $post_type Post type name. * @return string Default rendering mode for the post type. diff --git a/lib/compat/wordpress-6.7/post.php b/lib/compat/wordpress-6.7/post.php index 945041ba0d6bf..1ea0f3d8479ac 100644 --- a/lib/compat/wordpress-6.7/post.php +++ b/lib/compat/wordpress-6.7/post.php @@ -17,11 +17,11 @@ * @return array Array of available rendering modes. */ function gutenberg_rendering_modes() { - return [ + return array( 'post-only', 'template-lock', 'template-locked', - ]; + ); } /** From 40ce65214c7cbadce2d83b5187c25d1a7f89fb54 Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Thu, 13 Jun 2024 11:22:34 -0400 Subject: [PATCH 16/44] Update rendering_modes function name to be prefixed with post_type_ --- .../class-gutenberg-rest-post-types-controller-6-7.php | 2 +- lib/compat/wordpress-6.7/post.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php b/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php index 6c87ef16bcaa0..99ae53c1f5d1f 100644 --- a/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php +++ b/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php @@ -48,7 +48,7 @@ public function prepare_item_for_response( $item, $request ) { $rendering_mode = apply_filters( 'post_type_default_rendering_mode', $rendering_mode, $item ); // Validate the filtered rendering mode. - if ( ! in_array( $rendering_mode, gutenberg_rendering_modes(), true ) ) { + if ( ! in_array( $rendering_mode, gutenberg_post_type_rendering_modes(), true ) ) { $rendering_mode = 'post-only'; } diff --git a/lib/compat/wordpress-6.7/post.php b/lib/compat/wordpress-6.7/post.php index 1ea0f3d8479ac..7175fa9664006 100644 --- a/lib/compat/wordpress-6.7/post.php +++ b/lib/compat/wordpress-6.7/post.php @@ -16,7 +16,7 @@ * * @return array Array of available rendering modes. */ -function gutenberg_rendering_modes() { +function gutenberg_post_type_rendering_modes() { return array( 'post-only', 'template-lock', @@ -34,7 +34,7 @@ function gutenberg_rendering_modes() { */ function gutenberg_post_type_default_rendering_mode( $args, $post_type ) { $rendering_mode = 'page' === $post_type ? 'template-locked' : 'post-only'; - $rendering_modes = gutenberg_rendering_modes(); + $rendering_modes = gutenberg_post_type_rendering_modes(); // Make sure the post type supports the block editor. if ( From a0a766c77b3872b46dc2d3abd3333926cb565000 Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Thu, 18 Jul 2024 12:25:00 -0400 Subject: [PATCH 17/44] Create new setRenderingMode playwright utility to reset the rendering mode for tests --- .../src/admin/create-new-post.ts | 4 ++++ .../src/editor/index.ts | 3 +++ .../src/editor/set-rendering-mode.ts | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 packages/e2e-test-utils-playwright/src/editor/set-rendering-mode.ts diff --git a/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts b/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts index a5d6617946ae3..df6cfdad2d474 100644 --- a/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts +++ b/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts @@ -38,8 +38,12 @@ export async function createNewPost( query.set( 'excerpt', excerpt ); } + // Navigate to the new post page. await this.visitAdminPage( 'post-new.php', query.toString() ); + // Set editing mode + await this.editor.setRenderingMode(); + await this.editor.setPreferences( 'core/edit-post', { welcomeGuide: options.showWelcomeGuide ?? false, fullscreenMode: options.fullscreenMode ?? false, diff --git a/packages/e2e-test-utils-playwright/src/editor/index.ts b/packages/e2e-test-utils-playwright/src/editor/index.ts index c222f68aecc90..2a142ea63c866 100644 --- a/packages/e2e-test-utils-playwright/src/editor/index.ts +++ b/packages/e2e-test-utils-playwright/src/editor/index.ts @@ -26,6 +26,7 @@ import { setPreferences } from './set-preferences'; import { showBlockToolbar } from './show-block-toolbar'; import { saveSiteEditorEntities } from './site-editor'; import { setIsFixedToolbar } from './set-is-fixed-toolbar'; +import { setRenderingMode } from './set-rendering-mode'; import { switchToLegacyCanvas } from './switch-to-legacy-canvas'; import { transformBlockTo } from './transform-block-to'; @@ -84,6 +85,8 @@ export class Editor { /** @borrows setIsFixedToolbar as this.setIsFixedToolbar */ setIsFixedToolbar: typeof setIsFixedToolbar = setIsFixedToolbar.bind( this ); + /** @borrows setRenderingMode as this.setRenderingMode */ + setRenderingMode: typeof setRenderingMode = setRenderingMode.bind( this ); /** @borrows switchToLegacyCanvas as this.switchToLegacyCanvas */ switchToLegacyCanvas: typeof switchToLegacyCanvas = switchToLegacyCanvas.bind( this ); diff --git a/packages/e2e-test-utils-playwright/src/editor/set-rendering-mode.ts b/packages/e2e-test-utils-playwright/src/editor/set-rendering-mode.ts new file mode 100644 index 0000000000000..2c043dad4a970 --- /dev/null +++ b/packages/e2e-test-utils-playwright/src/editor/set-rendering-mode.ts @@ -0,0 +1,18 @@ +/** + * Internal dependencies + */ +import type { Editor } from './index'; + +/** + * Set the rendering mode of the editor. + * + * @param this + */ +async function setRenderingMode( this: Editor ) { + await this.page.waitForFunction( () => window?.wp?.data ); + + // Set editing mode + window.wp.data.dispatch( 'core/editor' ).setRenderingMode( 'post-only' ); +} + +export { setRenderingMode }; From 882f69c3984c04d3e115778f015d7f5513bc8c51 Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Thu, 18 Jul 2024 13:16:41 -0400 Subject: [PATCH 18/44] evaluate the page before attempting to access global variables --- .../src/editor/set-rendering-mode.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/e2e-test-utils-playwright/src/editor/set-rendering-mode.ts b/packages/e2e-test-utils-playwright/src/editor/set-rendering-mode.ts index 2c043dad4a970..9f193e20fd042 100644 --- a/packages/e2e-test-utils-playwright/src/editor/set-rendering-mode.ts +++ b/packages/e2e-test-utils-playwright/src/editor/set-rendering-mode.ts @@ -11,8 +11,12 @@ import type { Editor } from './index'; async function setRenderingMode( this: Editor ) { await this.page.waitForFunction( () => window?.wp?.data ); - // Set editing mode - window.wp.data.dispatch( 'core/editor' ).setRenderingMode( 'post-only' ); + await this.page.evaluate( () => { + // Set editing mode + window.wp.data + .dispatch( 'core/editor' ) + .setRenderingMode( 'post-only' ); + } ); } export { setRenderingMode }; From 3496d556f1f19664c00885b1d63cc8c793974494 Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Thu, 18 Jul 2024 15:33:27 -0400 Subject: [PATCH 19/44] Add rendering mode parameter to the setRenderingMode utility --- .../src/admin/create-new-post.ts | 3 +-- .../src/editor/set-rendering-mode.ts | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts b/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts index df6cfdad2d474..f6947d5e7ca14 100644 --- a/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts +++ b/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts @@ -41,8 +41,7 @@ export async function createNewPost( // Navigate to the new post page. await this.visitAdminPage( 'post-new.php', query.toString() ); - // Set editing mode - await this.editor.setRenderingMode(); + await this.editor.setRenderingMode( 'post-only' ); await this.editor.setPreferences( 'core/edit-post', { welcomeGuide: options.showWelcomeGuide ?? false, diff --git a/packages/e2e-test-utils-playwright/src/editor/set-rendering-mode.ts b/packages/e2e-test-utils-playwright/src/editor/set-rendering-mode.ts index 9f193e20fd042..7b41eede7cf79 100644 --- a/packages/e2e-test-utils-playwright/src/editor/set-rendering-mode.ts +++ b/packages/e2e-test-utils-playwright/src/editor/set-rendering-mode.ts @@ -7,16 +7,17 @@ import type { Editor } from './index'; * Set the rendering mode of the editor. * * @param this + * @param mode The rendering mode to set. */ -async function setRenderingMode( this: Editor ) { +async function setRenderingMode( this: Editor, mode: string = 'post-only' ) { await this.page.waitForFunction( () => window?.wp?.data ); - await this.page.evaluate( () => { + await this.page.evaluate( ( renderingMode ) => { // Set editing mode window.wp.data .dispatch( 'core/editor' ) - .setRenderingMode( 'post-only' ); - } ); + .setRenderingMode( renderingMode ); + }, mode ); } export { setRenderingMode }; From 65c264bcb935433a1a4579d7f428decbd903dd68 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Tue, 30 Jul 2024 21:56:49 +0530 Subject: [PATCH 20/44] check if active theme is block theme --- lib/compat/wordpress-6.7/post.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/compat/wordpress-6.7/post.php b/lib/compat/wordpress-6.7/post.php index 7175fa9664006..d89dc7b458a98 100644 --- a/lib/compat/wordpress-6.7/post.php +++ b/lib/compat/wordpress-6.7/post.php @@ -38,6 +38,7 @@ function gutenberg_post_type_default_rendering_mode( $args, $post_type ) { // Make sure the post type supports the block editor. if ( + wp_is_block_theme() && ( isset( $args['show_in_rest'] ) && $args['show_in_rest'] ) && ( isset( $args['supports'] ) && in_array( 'editor', $args['supports'], true ) ) ) { From a27c07e680f1966860c31727f47dc12d747dfff3 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Wed, 31 Jul 2024 00:02:32 +0530 Subject: [PATCH 21/44] fix broken test --- test/e2e/specs/site-editor/command-center.spec.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/e2e/specs/site-editor/command-center.spec.js b/test/e2e/specs/site-editor/command-center.spec.js index fce951ca767be..ebda424a86c54 100644 --- a/test/e2e/specs/site-editor/command-center.spec.js +++ b/test/e2e/specs/site-editor/command-center.spec.js @@ -30,6 +30,17 @@ test.describe( 'Site editor command palette', () => { await expect( page ).toHaveURL( '/wp-admin/post-new.php?post_type=page' ); + await page.evaluate( () => { + window.wp.data + .dispatch( 'core/preferences' ) + .set( 'core/edit-post', 'welcomeGuide', false ); + }, false ); + await page.getByLabel( 'Template options' ).click(); + + await page + .getByRole( 'menuitemcheckbox', { name: 'Show template' } ) + .click(); + await expect( editor.canvas.getByRole( 'textbox', { name: 'Add title' } ) ).toBeVisible(); From 3619aed2d8da504575bb679e6388ece0851659af Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Fri, 2 Aug 2024 14:57:57 -0400 Subject: [PATCH 22/44] Add core backport changelog entry --- backport-changelog/6.7/7129.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 backport-changelog/6.7/7129.md diff --git a/backport-changelog/6.7/7129.md b/backport-changelog/6.7/7129.md new file mode 100644 index 0000000000000..90c9168cdc6f8 --- /dev/null +++ b/backport-changelog/6.7/7129.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/7129 + +* https://github.com/WordPress/gutenberg/pull/62304 From b0800134922e43ba352cf4970d7d67967da3cf5b Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Fri, 2 Aug 2024 15:04:42 -0400 Subject: [PATCH 23/44] Adjust order of rendering_mode filters --- ...gutenberg-rest-post-types-controller-6-7.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php b/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php index 99ae53c1f5d1f..d7e655ff91db5 100644 --- a/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php +++ b/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php @@ -26,26 +26,27 @@ public function prepare_item_for_response( $item, $request ) { // Property will only exist if the post type supports the block editor. if ( 'edit' === $context && property_exists( $item, 'default_rendering_mode' ) ) { /** - * Filters the block editor rendering mode for a specific post type. - * - * The dynamic portion of the hook name, `$item->name`, refers to the post type slug. + * Filters the block editor rendering mode for a post type. * * @since 6.7.0 * @param string $default_rendering_mode Default rendering mode for the post type. - * @param WP_Post_Type $post_type Post type object. + * @param WP_Post_Type $post_type Post type name. * @return string Default rendering mode for the post type. */ - $rendering_mode = apply_filters( "post_type_{$item->name}_default_rendering_mode", $item->default_rendering_mode, $item ); + $rendering_mode = apply_filters( 'post_type_default_rendering_mode', $item->default_rendering_mode, $item ); /** - * Filters the block editor rendering mode for a post type. + * Filters the block editor rendering mode for a specific post type. + * Applied after the generic `post_type_default_rendering_mode` filter. + * + * The dynamic portion of the hook name, `$item->name`, refers to the post type slug. * * @since 6.7.0 * @param string $default_rendering_mode Default rendering mode for the post type. - * @param WP_Post_Type $post_type Post type name. + * @param WP_Post_Type $post_type Post type object. * @return string Default rendering mode for the post type. */ - $rendering_mode = apply_filters( 'post_type_default_rendering_mode', $rendering_mode, $item ); + $rendering_mode = apply_filters( "post_type_{$item->name}_default_rendering_mode", $rendering_mode, $item ); // Validate the filtered rendering mode. if ( ! in_array( $rendering_mode, gutenberg_post_type_rendering_modes(), true ) ) { From 5d9a3f4ce52d254cf5a3f9043ef272b9441129d0 Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Tue, 20 Aug 2024 10:53:18 -0400 Subject: [PATCH 24/44] Set the editor rendering mode when a page is created for the performance tests --- .../e2e-test-utils-playwright/src/admin/create-new-post.ts | 7 +++++-- test/performance/specs/site-editor.spec.js | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts b/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts index f6947d5e7ca14..58d163d1888ad 100644 --- a/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts +++ b/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts @@ -10,6 +10,7 @@ interface NewPostOptions { excerpt?: string; showWelcomeGuide?: boolean; fullscreenMode?: boolean; + renderingMode?: string; } /** @@ -23,7 +24,7 @@ export async function createNewPost( options: NewPostOptions = {} ) { const query = new URLSearchParams(); - const { postType, title, content, excerpt } = options; + const { postType, title, content, excerpt, renderingMode } = options; if ( postType ) { query.set( 'post_type', postType ); @@ -41,7 +42,9 @@ export async function createNewPost( // Navigate to the new post page. await this.visitAdminPage( 'post-new.php', query.toString() ); - await this.editor.setRenderingMode( 'post-only' ); + // Set rendering mode. + const postRenderingMode = renderingMode ?? 'post-only'; + await this.editor.setRenderingMode( postRenderingMode ); await this.editor.setPreferences( 'core/edit-post', { welcomeGuide: options.showWelcomeGuide ?? false, diff --git a/test/performance/specs/site-editor.spec.js b/test/performance/specs/site-editor.spec.js index 9c9d8aec71da4..6746b513618cf 100644 --- a/test/performance/specs/site-editor.spec.js +++ b/test/performance/specs/site-editor.spec.js @@ -63,7 +63,10 @@ test.describe( 'Site Editor Performance', () => { let draftId = null; test( 'Setup the test page', async ( { admin, perfUtils } ) => { - await admin.createNewPost( { postType: 'page' } ); + await admin.createNewPost( { + postType: 'page', + renderingMode: 'template-lock', + } ); await perfUtils.loadBlocksForLargePost(); draftId = await perfUtils.saveDraft(); From 4967bf02a470889fc51b08851ac30d74f12a7950 Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Tue, 20 Aug 2024 15:31:35 -0400 Subject: [PATCH 25/44] write setEditorRenderingMode method for playwright performance tests --- .../src/admin/create-new-post.ts | 5 ++-- test/performance/fixtures/perf-utils.ts | 25 +++++++++++++++++++ test/performance/specs/site-editor.spec.js | 6 ++--- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts b/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts index 58d163d1888ad..0822cee33b10d 100644 --- a/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts +++ b/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts @@ -24,7 +24,7 @@ export async function createNewPost( options: NewPostOptions = {} ) { const query = new URLSearchParams(); - const { postType, title, content, excerpt, renderingMode } = options; + const { postType, title, content, excerpt } = options; if ( postType ) { query.set( 'post_type', postType ); @@ -43,8 +43,7 @@ export async function createNewPost( await this.visitAdminPage( 'post-new.php', query.toString() ); // Set rendering mode. - const postRenderingMode = renderingMode ?? 'post-only'; - await this.editor.setRenderingMode( postRenderingMode ); + await this.editor.setRenderingMode( 'post-only' ); await this.editor.setPreferences( 'core/edit-post', { welcomeGuide: options.showWelcomeGuide ?? false, diff --git a/test/performance/fixtures/perf-utils.ts b/test/performance/fixtures/perf-utils.ts index 83213a59520dd..9a1baacc81116 100644 --- a/test/performance/fixtures/perf-utils.ts +++ b/test/performance/fixtures/perf-utils.ts @@ -65,6 +65,31 @@ export class PerfUtils { return postId; } + /** + * Set the rendering mode of the post. + * + * @param renderingMode The rendering mode to set. + */ + async setRenderingMode( renderingMode: string = 'post-only' ) { + await this.page.waitForFunction( () => window?.wp?.data ); + + await this.page.evaluate( () => { + window.wp.data + .dispatch( 'core/preferences' ) + .set( 'core/edit-post', 'welcomeGuide', false ); + }, false ); + await this.page.getByLabel( 'Template options' ).click(); + + let postRenderingModeLabel = 'Edit template'; + if ( renderingMode !== 'post-only' ) { + postRenderingModeLabel = 'Show template'; + } + + await this.page + .getByRole( 'menuitemcheckbox', { name: postRenderingModeLabel } ) + .click(); + } + /** * Disables the editor autosave function. */ diff --git a/test/performance/specs/site-editor.spec.js b/test/performance/specs/site-editor.spec.js index 6746b513618cf..0ba9d4188a2d5 100644 --- a/test/performance/specs/site-editor.spec.js +++ b/test/performance/specs/site-editor.spec.js @@ -63,10 +63,8 @@ test.describe( 'Site Editor Performance', () => { let draftId = null; test( 'Setup the test page', async ( { admin, perfUtils } ) => { - await admin.createNewPost( { - postType: 'page', - renderingMode: 'template-lock', - } ); + await admin.createNewPost( { postType: 'page' } ); + await perfUtils.setRenderingMode( 'template-lock' ); await perfUtils.loadBlocksForLargePost(); draftId = await perfUtils.saveDraft(); From 7e72459c4c5b23f65a99a88ed34eaf8aeacea65c Mon Sep 17 00:00:00 2001 From: Tyler Bailey Date: Wed, 21 Aug 2024 14:06:44 -0400 Subject: [PATCH 26/44] Fix the rendering mode switcher for performance tests --- .../provider/use-block-editor-settings.js | 2 +- test/performance/fixtures/perf-utils.ts | 18 +++--------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/packages/editor/src/components/provider/use-block-editor-settings.js b/packages/editor/src/components/provider/use-block-editor-settings.js index 6aa2763cf9db0..554b35ac9af8b 100644 --- a/packages/editor/src/components/provider/use-block-editor-settings.js +++ b/packages/editor/src/components/provider/use-block-editor-settings.js @@ -141,7 +141,7 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) { : undefined; function getSectionRootBlock() { - if ( renderingMode === 'template-locked' ) { + if ( renderingMode.includes( 'template-lock' ) ) { return getBlocksByName( 'core/post-content' )?.[ 0 ] ?? ''; } diff --git a/test/performance/fixtures/perf-utils.ts b/test/performance/fixtures/perf-utils.ts index 9a1baacc81116..f1b3d3252d247 100644 --- a/test/performance/fixtures/perf-utils.ts +++ b/test/performance/fixtures/perf-utils.ts @@ -73,21 +73,9 @@ export class PerfUtils { async setRenderingMode( renderingMode: string = 'post-only' ) { await this.page.waitForFunction( () => window?.wp?.data ); - await this.page.evaluate( () => { - window.wp.data - .dispatch( 'core/preferences' ) - .set( 'core/edit-post', 'welcomeGuide', false ); - }, false ); - await this.page.getByLabel( 'Template options' ).click(); - - let postRenderingModeLabel = 'Edit template'; - if ( renderingMode !== 'post-only' ) { - postRenderingModeLabel = 'Show template'; - } - - await this.page - .getByRole( 'menuitemcheckbox', { name: postRenderingModeLabel } ) - .click(); + await this.page.evaluate( ( mode ) => { + window.wp.data.dispatch( 'core/editor' ).setRenderingMode( mode ); + }, renderingMode ); } /** From a55cd6852c10dc02ec84217f4c71d9ff1cc39f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Thu, 14 Nov 2024 23:45:33 +0100 Subject: [PATCH 27/44] fix move files to 6.8 compat folder --- lib/compat/wordpress-6.7/rest-api.php | 11 ---------- ...enberg-rest-post-types-controller-6-8.php} | 10 ++++----- lib/compat/wordpress-6.8/rest-api.php | 22 +++++++++++++++++++ lib/load.php | 3 ++- 4 files changed, 29 insertions(+), 17 deletions(-) rename lib/compat/{wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php => wordpress-6.8/class-gutenberg-rest-post-types-controller-6-8.php} (90%) create mode 100644 lib/compat/wordpress-6.8/rest-api.php diff --git a/lib/compat/wordpress-6.7/rest-api.php b/lib/compat/wordpress-6.7/rest-api.php index 29c718304155d..741d0ad1805e0 100644 --- a/lib/compat/wordpress-6.7/rest-api.php +++ b/lib/compat/wordpress-6.7/rest-api.php @@ -10,17 +10,6 @@ die( 'Silence is golden.' ); } -if ( ! function_exists( 'gutenberg_add_post_type_rendering_mode' ) ) { - /** - * Add Block Editor default rendering mode to the post type response. - */ - function gutenberg_add_post_type_rendering_mode() { - $controller = new Gutenberg_REST_Post_Types_Controller_6_7(); - $controller->register_routes(); - } -} -add_action( 'rest_api_init', 'gutenberg_add_post_type_rendering_mode' ); - /** * Update the preload paths registered in Core (`site-editor.php` or `edit-form-blocks.php`). * diff --git a/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php b/lib/compat/wordpress-6.8/class-gutenberg-rest-post-types-controller-6-8.php similarity index 90% rename from lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php rename to lib/compat/wordpress-6.8/class-gutenberg-rest-post-types-controller-6-8.php index d7e655ff91db5..a596bc085694d 100644 --- a/lib/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php +++ b/lib/compat/wordpress-6.8/class-gutenberg-rest-post-types-controller-6-8.php @@ -1,17 +1,17 @@ name`, refers to the post type slug. * - * @since 6.7.0 + * @since 6.8.0 * @param string $default_rendering_mode Default rendering mode for the post type. * @param WP_Post_Type $post_type Post type object. * @return string Default rendering mode for the post type. diff --git a/lib/compat/wordpress-6.8/rest-api.php b/lib/compat/wordpress-6.8/rest-api.php new file mode 100644 index 0000000000000..da1b657cda078 --- /dev/null +++ b/lib/compat/wordpress-6.8/rest-api.php @@ -0,0 +1,22 @@ +register_routes(); + } +} +add_action( 'rest_api_init', 'gutenberg_add_post_type_rendering_mode' ); diff --git a/lib/load.php b/lib/load.php index ea53b389a2a0e..4912fb8d1909d 100644 --- a/lib/load.php +++ b/lib/load.php @@ -41,7 +41,6 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-6.6/rest-api.php'; // WordPress 6.7 compat. - require __DIR__ . '/compat/wordpress-6.7/class-gutenberg-rest-post-types-controller-6-7.php'; require __DIR__ . '/compat/wordpress-6.7/class-gutenberg-rest-posts-controller-6-7.php'; require __DIR__ . '/compat/wordpress-6.7/class-gutenberg-rest-templates-controller-6-7.php'; require __DIR__ . '/compat/wordpress-6.7/class-gutenberg-rest-server.php'; @@ -50,6 +49,8 @@ function gutenberg_is_experiment_enabled( $name ) { // WordPress 6.8 compat. require __DIR__ . '/compat/wordpress-6.8/block-comments.php'; require __DIR__ . '/compat/wordpress-6.8/class-gutenberg-rest-comment-controller-6-8.php'; + require __DIR__ . '/compat/wordpress-6.8/class-gutenberg-rest-post-types-controller-6-8.php'; + require __DIR__ . '/compat/wordpress-6.8/rest-api.php'; // Plugin specific code. require_once __DIR__ . '/class-wp-rest-global-styles-controller-gutenberg.php'; From 429b338d2df584c0eaee42da3ff193b1920d8d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Thu, 14 Nov 2024 23:50:43 +0100 Subject: [PATCH 28/44] fix move to 6.8 folder --- lib/compat/{wordpress-6.7 => wordpress-6.8}/post.php | 0 lib/load.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename lib/compat/{wordpress-6.7 => wordpress-6.8}/post.php (100%) diff --git a/lib/compat/wordpress-6.7/post.php b/lib/compat/wordpress-6.8/post.php similarity index 100% rename from lib/compat/wordpress-6.7/post.php rename to lib/compat/wordpress-6.8/post.php diff --git a/lib/load.php b/lib/load.php index 4912fb8d1909d..100160176f391 100644 --- a/lib/load.php +++ b/lib/load.php @@ -110,7 +110,6 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-6.6/post.php'; // WordPress 6.7 compat. -require __DIR__ . '/compat/wordpress-6.7/post.php'; require __DIR__ . '/compat/wordpress-6.7/block-templates.php'; require __DIR__ . '/compat/wordpress-6.7/blocks.php'; require __DIR__ . '/compat/wordpress-6.7/block-bindings.php'; @@ -123,6 +122,7 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-6.8/preload.php'; require __DIR__ . '/compat/wordpress-6.8/blocks.php'; require __DIR__ . '/compat/wordpress-6.8/functions.php'; +require __DIR__ . '/compat/wordpress-6.8/post.php'; // Experimental features. require __DIR__ . '/experimental/block-editor-settings-mobile.php'; From d523598355b491dee4dd03abadc50b785c7276cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Thu, 14 Nov 2024 23:56:13 +0100 Subject: [PATCH 29/44] fix reset test overrides --- .../src/admin/create-new-post.ts | 4 ---- .../src/editor/index.ts | 3 --- .../src/editor/set-rendering-mode.ts | 23 ------------------- .../specs/site-editor/command-center.spec.js | 10 -------- test/performance/fixtures/perf-utils.ts | 13 ----------- test/performance/specs/site-editor.spec.js | 1 - 6 files changed, 54 deletions(-) delete mode 100644 packages/e2e-test-utils-playwright/src/editor/set-rendering-mode.ts diff --git a/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts b/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts index 0822cee33b10d..6e34488d4c09a 100644 --- a/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts +++ b/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts @@ -10,7 +10,6 @@ interface NewPostOptions { excerpt?: string; showWelcomeGuide?: boolean; fullscreenMode?: boolean; - renderingMode?: string; } /** @@ -42,9 +41,6 @@ export async function createNewPost( // Navigate to the new post page. await this.visitAdminPage( 'post-new.php', query.toString() ); - // Set rendering mode. - await this.editor.setRenderingMode( 'post-only' ); - await this.editor.setPreferences( 'core/edit-post', { welcomeGuide: options.showWelcomeGuide ?? false, fullscreenMode: options.fullscreenMode ?? false, diff --git a/packages/e2e-test-utils-playwright/src/editor/index.ts b/packages/e2e-test-utils-playwright/src/editor/index.ts index 408f7c1daba28..4ed32134f0979 100644 --- a/packages/e2e-test-utils-playwright/src/editor/index.ts +++ b/packages/e2e-test-utils-playwright/src/editor/index.ts @@ -26,7 +26,6 @@ import { setPreferences } from './set-preferences'; import { showBlockToolbar } from './show-block-toolbar'; import { saveSiteEditorEntities } from './site-editor'; import { setIsFixedToolbar } from './set-is-fixed-toolbar'; -import { setRenderingMode } from './set-rendering-mode'; import { switchToLegacyCanvas } from './switch-to-legacy-canvas'; import { transformBlockTo } from './transform-block-to'; import { switchEditorTool } from './switch-editor-tool'; @@ -86,8 +85,6 @@ export class Editor { /** @borrows setIsFixedToolbar as this.setIsFixedToolbar */ setIsFixedToolbar: typeof setIsFixedToolbar = setIsFixedToolbar.bind( this ); - /** @borrows setRenderingMode as this.setRenderingMode */ - setRenderingMode: typeof setRenderingMode = setRenderingMode.bind( this ); /** @borrows switchEditorTool as this.switchEditorTool */ switchEditorTool: typeof switchEditorTool = switchEditorTool.bind( this ); /** @borrows switchToLegacyCanvas as this.switchToLegacyCanvas */ diff --git a/packages/e2e-test-utils-playwright/src/editor/set-rendering-mode.ts b/packages/e2e-test-utils-playwright/src/editor/set-rendering-mode.ts deleted file mode 100644 index 7b41eede7cf79..0000000000000 --- a/packages/e2e-test-utils-playwright/src/editor/set-rendering-mode.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Internal dependencies - */ -import type { Editor } from './index'; - -/** - * Set the rendering mode of the editor. - * - * @param this - * @param mode The rendering mode to set. - */ -async function setRenderingMode( this: Editor, mode: string = 'post-only' ) { - await this.page.waitForFunction( () => window?.wp?.data ); - - await this.page.evaluate( ( renderingMode ) => { - // Set editing mode - window.wp.data - .dispatch( 'core/editor' ) - .setRenderingMode( renderingMode ); - }, mode ); -} - -export { setRenderingMode }; diff --git a/test/e2e/specs/site-editor/command-center.spec.js b/test/e2e/specs/site-editor/command-center.spec.js index 132aba7fb9808..0ab44af0dfae1 100644 --- a/test/e2e/specs/site-editor/command-center.spec.js +++ b/test/e2e/specs/site-editor/command-center.spec.js @@ -30,16 +30,6 @@ test.describe( 'Site editor command palette', () => { await expect( page ).toHaveURL( /\/wp-admin\/site-editor.php\?postId=(\d+)&postType=page&canvas=edit/ ); - await page.evaluate( () => { - window.wp.data - .dispatch( 'core/preferences' ) - .set( 'core/edit-post', 'welcomeGuide', false ); - }, false ); - await page.getByLabel( 'Template options' ).click(); - - await page - .getByRole( 'menuitemcheckbox', { name: 'Show template' } ) - .click(); await expect( editor.canvas diff --git a/test/performance/fixtures/perf-utils.ts b/test/performance/fixtures/perf-utils.ts index 13bdfefac7810..592e8194852e3 100644 --- a/test/performance/fixtures/perf-utils.ts +++ b/test/performance/fixtures/perf-utils.ts @@ -65,19 +65,6 @@ export class PerfUtils { return postId; } - /** - * Set the rendering mode of the post. - * - * @param renderingMode The rendering mode to set. - */ - async setRenderingMode( renderingMode: string = 'post-only' ) { - await this.page.waitForFunction( () => window?.wp?.data ); - - await this.page.evaluate( ( mode ) => { - window.wp.data.dispatch( 'core/editor' ).setRenderingMode( mode ); - }, renderingMode ); - } - /** * Disables the editor autosave function. */ diff --git a/test/performance/specs/site-editor.spec.js b/test/performance/specs/site-editor.spec.js index 0ba9d4188a2d5..9c9d8aec71da4 100644 --- a/test/performance/specs/site-editor.spec.js +++ b/test/performance/specs/site-editor.spec.js @@ -64,7 +64,6 @@ test.describe( 'Site Editor Performance', () => { test( 'Setup the test page', async ( { admin, perfUtils } ) => { await admin.createNewPost( { postType: 'page' } ); - await perfUtils.setRenderingMode( 'template-lock' ); await perfUtils.loadBlocksForLargePost(); draftId = await perfUtils.saveDraft(); From 41601ecc7a02ee21c3ad59eb059c0179c74ce952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Thu, 14 Nov 2024 23:57:01 +0100 Subject: [PATCH 30/44] fix reset whitespace changes --- lib/compat/wordpress-6.6/post.php | 1 + lib/compat/wordpress-6.6/rest-api.php | 1 + .../class-gutenberg-rest-post-types-controller-6-8.php | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/compat/wordpress-6.6/post.php b/lib/compat/wordpress-6.6/post.php index 857ac6fc7d9ed..8415f3bf42f18 100644 --- a/lib/compat/wordpress-6.6/post.php +++ b/lib/compat/wordpress-6.6/post.php @@ -11,6 +11,7 @@ function gutenberg_add_excerpt_support_to_wp_block() { add_post_type_support( 'wp_block', 'excerpt' ); } + add_action( 'init', 'gutenberg_add_excerpt_support_to_wp_block' ); /** diff --git a/lib/compat/wordpress-6.6/rest-api.php b/lib/compat/wordpress-6.6/rest-api.php index 6d2b2eda00732..eadd3b1d376a7 100644 --- a/lib/compat/wordpress-6.6/rest-api.php +++ b/lib/compat/wordpress-6.6/rest-api.php @@ -77,6 +77,7 @@ function gutenberg_add_class_list_to_public_post_types() { } add_action( 'rest_api_init', 'gutenberg_add_class_list_to_public_post_types' ); + /** * Registers the Global Styles Revisions REST API routes. */ diff --git a/lib/compat/wordpress-6.8/class-gutenberg-rest-post-types-controller-6-8.php b/lib/compat/wordpress-6.8/class-gutenberg-rest-post-types-controller-6-8.php index a596bc085694d..da0489210e21f 100644 --- a/lib/compat/wordpress-6.8/class-gutenberg-rest-post-types-controller-6-8.php +++ b/lib/compat/wordpress-6.8/class-gutenberg-rest-post-types-controller-6-8.php @@ -15,8 +15,8 @@ class Gutenberg_REST_Post_Types_Controller_6_8 extends WP_REST_Post_Types_Contro /** * Add Block Editor default rendering mode setting to the response. * - * @param WP_Post_Type $item Post type object. - * @param WP_REST_Request $request Request object. + * @param WP_Post_Type $item Post type object. + * @param WP_REST_Request $request Request object. * @return WP_REST_Response Response object. */ public function prepare_item_for_response( $item, $request ) { From 05abd417aa7205cce3354177db2675a23ef88a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Fri, 15 Nov 2024 00:01:49 +0100 Subject: [PATCH 31/44] fix reset whitespace changes --- packages/e2e-test-utils-playwright/src/admin/create-new-post.ts | 1 - test/e2e/specs/site-editor/command-center.spec.js | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts b/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts index 6e34488d4c09a..a5d6617946ae3 100644 --- a/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts +++ b/packages/e2e-test-utils-playwright/src/admin/create-new-post.ts @@ -38,7 +38,6 @@ export async function createNewPost( query.set( 'excerpt', excerpt ); } - // Navigate to the new post page. await this.visitAdminPage( 'post-new.php', query.toString() ); await this.editor.setPreferences( 'core/edit-post', { diff --git a/test/e2e/specs/site-editor/command-center.spec.js b/test/e2e/specs/site-editor/command-center.spec.js index 0ab44af0dfae1..19318081aa171 100644 --- a/test/e2e/specs/site-editor/command-center.spec.js +++ b/test/e2e/specs/site-editor/command-center.spec.js @@ -30,7 +30,6 @@ test.describe( 'Site editor command palette', () => { await expect( page ).toHaveURL( /\/wp-admin\/site-editor.php\?postId=(\d+)&postType=page&canvas=edit/ ); - await expect( editor.canvas .getByLabel( 'Block: Title' ) From 4904b5a3040b12f79d26bd451de6ee2652bdef52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Fri, 15 Nov 2024 00:03:46 +0100 Subject: [PATCH 32/44] fix reset whitespace --- packages/block-library/src/image/block.json | 9 +-------- packages/block-library/src/post-content/block.json | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/block-library/src/image/block.json b/packages/block-library/src/image/block.json index 26835df9e856c..16e3121747602 100644 --- a/packages/block-library/src/image/block.json +++ b/packages/block-library/src/image/block.json @@ -4,14 +4,7 @@ "name": "core/image", "title": "Image", "category": "media", - "usesContext": [ - "allowResize", - "imageCrop", - "fixedHeight", - "postId", - "postType", - "queryId" - ], + "usesContext": [ "allowResize", "imageCrop", "fixedHeight", "postId", "postType", "queryId" ], "description": "Insert an image to make a visual statement.", "keywords": [ "img", "photo", "picture" ], "textdomain": "default", diff --git a/packages/block-library/src/post-content/block.json b/packages/block-library/src/post-content/block.json index e5d455b97a8a3..ed9c47154b2f8 100644 --- a/packages/block-library/src/post-content/block.json +++ b/packages/block-library/src/post-content/block.json @@ -69,4 +69,4 @@ }, "style": "wp-block-post-content", "editorStyle": "wp-block-post-content-editor" -} +} \ No newline at end of file From 40d7324faf1e7c803d9be4e4b4208df06527fc3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Fri, 15 Nov 2024 00:08:47 +0100 Subject: [PATCH 33/44] fix reset change of if condition --- .../editor/src/components/provider/use-block-editor-settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor/src/components/provider/use-block-editor-settings.js b/packages/editor/src/components/provider/use-block-editor-settings.js index 5333eebbf7237..f5c45f431e2c8 100644 --- a/packages/editor/src/components/provider/use-block-editor-settings.js +++ b/packages/editor/src/components/provider/use-block-editor-settings.js @@ -143,7 +143,7 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) { : undefined; function getSectionRootBlock() { - if ( renderingMode.includes( 'template-lock' ) ) { + if ( renderingMode === 'template-locked' ) { return getBlocksByName( 'core/post-content' )?.[ 0 ] ?? ''; } From c2d58a98c88da0dc9ba0c7bbbcaf8bb49f552042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Fri, 15 Nov 2024 00:14:30 +0100 Subject: [PATCH 34/44] fix ensure post type object has loaded before editor renders --- .../editor/src/components/provider/index.js | 65 +++++++++++-------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index 9a7381211d8ad..5c7a2c9a65a95 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -164,35 +164,44 @@ export const ExperimentalEditorProvider = withRegistryProvider( BlockEditorProviderComponent = ExperimentalBlockEditorProvider, __unstableTemplate: template, } ) => { - const { editorSettings, selection, isReady, mode, postTypeEntities } = - useSelect( - ( select ) => { - const { - getEditorSettings, - getEditorSelection, - __unstableIsEditorReady, - } = select( editorStore ); - const { getEntitiesConfig } = select( coreStore ); + const { + editorSettings, + selection, + isReady, + mode, + postTypeEntities, + hasLoadedPostObject, + } = useSelect( + ( select ) => { + const { + getEditorSettings, + getEditorSelection, + __unstableIsEditorReady, + } = select( editorStore ); + const { getEntitiesConfig } = select( coreStore ); - const postTypeObject = select( coreStore ).getPostType( - post.type - ); + const postTypeObject = select( coreStore ).getPostType( + post.type + ); + + const _hasLoadedPostObject = select( + coreStore + ).hasFinishedResolution( 'getPostType', [ post.type ] ); - return { - editorSettings: getEditorSettings(), - isReady: __unstableIsEditorReady(), - mode: - postTypeObject?.default_rendering_mode ?? - 'post-only', - selection: getEditorSelection(), - postTypeEntities: - post.type === 'wp_template' - ? getEntitiesConfig( 'postType' ) - : null, - }; - }, - [ post.type ] - ); + return { + hasLoadedPostObject: _hasLoadedPostObject, + editorSettings: getEditorSettings(), + isReady: __unstableIsEditorReady(), + mode: postTypeObject?.default_rendering_mode ?? 'post-only', + selection: getEditorSelection(), + postTypeEntities: + post.type === 'wp_template' + ? getEntitiesConfig( 'postType' ) + : null, + }; + }, + [ post.type ] + ); const shouldRenderTemplate = !! template && mode !== 'post-only'; const rootLevelPost = shouldRenderTemplate ? template : post; const defaultBlockContext = useMemo( () => { @@ -322,7 +331,7 @@ export const ExperimentalEditorProvider = withRegistryProvider( // Register the editor commands. useCommands(); - if ( ! isReady || ! mode ) { + if ( ! isReady || ! mode || ! hasLoadedPostObject ) { return null; } From 9e8e08cb9ac60b93c8d4260f6c72a78f6d66e4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Fri, 15 Nov 2024 00:16:39 +0100 Subject: [PATCH 35/44] fix remove template-lock rendering mode --- lib/compat/wordpress-6.8/post.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/compat/wordpress-6.8/post.php b/lib/compat/wordpress-6.8/post.php index d89dc7b458a98..26e6c3adc07a3 100644 --- a/lib/compat/wordpress-6.8/post.php +++ b/lib/compat/wordpress-6.8/post.php @@ -19,7 +19,6 @@ function gutenberg_post_type_rendering_modes() { return array( 'post-only', - 'template-lock', 'template-locked', ); } From b94e30995b08639885bffd037e28dc189b707ccf Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Fri, 15 Nov 2024 10:04:22 +0100 Subject: [PATCH 36/44] Fix root post loading --- packages/editor/src/components/provider/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index 5c7a2c9a65a95..14f9c2dc7929f 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -72,8 +72,7 @@ const NON_CONTEXTUAL_POST_TYPES = [ * @return {Array} Block editor props. */ function useBlockEditorProps( post, template, mode ) { - const rootLevelPost = - mode === 'post-only' || ! template ? 'post' : 'template'; + const rootLevelPost = mode === 'template-locked' ? 'template' : 'post'; const [ postBlocks, onInput, onChange ] = useEntityBlockEditor( 'postType', post.type, From a742e4a8c4c0f9c2f8368924967210de680df95a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Fri, 15 Nov 2024 11:25:10 +0100 Subject: [PATCH 37/44] fix only apply default rendering mode on load --- packages/editor/src/components/provider/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index 14f9c2dc7929f..6c05e5b58235b 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -168,6 +168,7 @@ export const ExperimentalEditorProvider = withRegistryProvider( selection, isReady, mode, + defaultMode, postTypeEntities, hasLoadedPostObject, } = useSelect( @@ -175,6 +176,7 @@ export const ExperimentalEditorProvider = withRegistryProvider( const { getEditorSettings, getEditorSelection, + getRenderingMode, __unstableIsEditorReady, } = select( editorStore ); const { getEntitiesConfig } = select( coreStore ); @@ -191,7 +193,9 @@ export const ExperimentalEditorProvider = withRegistryProvider( hasLoadedPostObject: _hasLoadedPostObject, editorSettings: getEditorSettings(), isReady: __unstableIsEditorReady(), - mode: postTypeObject?.default_rendering_mode ?? 'post-only', + mode: getRenderingMode(), + defaultMode: + postTypeObject?.default_rendering_mode ?? 'post-only', selection: getEditorSelection(), postTypeEntities: post.type === 'wp_template' @@ -322,8 +326,8 @@ export const ExperimentalEditorProvider = withRegistryProvider( // Sets the right rendering mode when loading the editor. useEffect( () => { - setRenderingMode( mode ); - }, [ mode, setRenderingMode ] ); + setRenderingMode( defaultMode ); + }, [ defaultMode, setRenderingMode ] ); useHideBlocksFromInserter( post.type, mode ); From fcb14498909572e187dc58b0dcbdaa8b9cb60b33 Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Fri, 15 Nov 2024 12:07:16 -0500 Subject: [PATCH 38/44] fix: Expose rendering mode to mobile editor Recent changes in the editor provider enable setting the rendering mode via post type. The changes result conditionally rendering the visual editor until the mode is determined. Without the required reducers, the mobile editor never updated the rendering mode state, thus never rendering the visual editor. --- packages/editor/src/store/reducer.native.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/editor/src/store/reducer.native.js b/packages/editor/src/store/reducer.native.js index 7566dfc5dfd03..fbf6c968f57d0 100644 --- a/packages/editor/src/store/reducer.native.js +++ b/packages/editor/src/store/reducer.native.js @@ -9,6 +9,7 @@ import { combineReducers } from '@wordpress/data'; import { postId, postType, + renderingMode, saving, postLock, postSavingLock, @@ -82,6 +83,7 @@ export default combineReducers( { postId, postType, postTitle, + renderingMode, saving, postLock, postSavingLock, From ec543c5939e8459680c948c27f78221f3f95d933 Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Fri, 15 Nov 2024 16:27:10 -0500 Subject: [PATCH 39/44] test: Mobile editor mocks getPostType resolution The mobile editor only supports the `post-only` rendering mode, so we presume a resolved `getPostType` selector to unblock editor rendering. This is necessary as the editor provider awaits post type resolution before rendering the entirety of the editor. --- .../initialize-editor.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/native/integration-test-helpers/initialize-editor.js b/test/native/integration-test-helpers/initialize-editor.js index 511f0223e1135..3b89da979aee3 100644 --- a/test/native/integration-test-helpers/initialize-editor.js +++ b/test/native/integration-test-helpers/initialize-editor.js @@ -10,6 +10,8 @@ import { v4 as uuid } from 'uuid'; import { createElement, cloneElement } from '@wordpress/element'; // eslint-disable-next-line no-restricted-imports import { initializeEditor as internalInitializeEditor } from '@wordpress/edit-post'; +import { store as coreStore } from '@wordpress/core-data'; +import { select } from '@wordpress/data'; /** * Internal dependencies @@ -28,6 +30,21 @@ import { getGlobalStyles } from './get-global-styles'; * @return {import('@testing-library/react-native').RenderAPI} A Testing Library screen. */ export async function initializeEditor( props, { component } = {} ) { + const resolutionSpy = jest.spyOn( + select( coreStore ), + 'hasFinishedResolution' + ); + const actualResolution = resolutionSpy.getMockImplementation(); + resolutionSpy.mockImplementation( ( selectorName, args ) => { + // The mobile editor only supports the `post-only` rendering mode, so we + // presume a resolved `getPostType` selector to unblock editor rendering. + if ( 'getPostType' === selectorName ) { + return true; + } + + return actualResolution( selectorName, args ); + } ); + const uniqueId = uuid(); const postId = `post-id-${ uniqueId }`; const postType = 'post'; From 2aa288daf52bd6bb004bdc34a4af4177d4dc2268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Sat, 16 Nov 2024 00:06:30 +0100 Subject: [PATCH 40/44] attempt to fix performance tests by forcing `post-only` rendering mode whenever we load in the large post html file --- test/performance/fixtures/perf-utils.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/performance/fixtures/perf-utils.ts b/test/performance/fixtures/perf-utils.ts index 592e8194852e3..6766411e8ff32 100644 --- a/test/performance/fixtures/perf-utils.ts +++ b/test/performance/fixtures/perf-utils.ts @@ -133,6 +133,18 @@ export class PerfUtils { () => window?.wp?.blocks && window?.wp?.data ); + const initialRenderingMode = await this.page.evaluate( () => { + const { select } = window.wp.data; + return select( 'core/editor' ).getRenderingMode(); + } ); + + if ( initialRenderingMode !== 'post-only' ) { + await this.page.evaluate( () => { + const { dispatch } = window.wp.data; + dispatch( 'core/editor' ).setRenderingMode( 'post-only' ); + } ); + } + return await this.page.evaluate( ( html: string ) => { const { parse } = window.wp.blocks; const { dispatch } = window.wp.data; From 557ec18c66a8d5557cdeefc22ceefc0ecf062a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Tue, 19 Nov 2024 15:07:44 +0100 Subject: [PATCH 41/44] fix remove unused passed argument from useSpecificEditorSettings call --- packages/edit-site/src/components/editor/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/edit-site/src/components/editor/index.js b/packages/edit-site/src/components/editor/index.js index 51d734f25c6ad..1d115dca7518d 100644 --- a/packages/edit-site/src/components/editor/index.js +++ b/packages/edit-site/src/components/editor/index.js @@ -131,9 +131,7 @@ export default function EditSiteEditor( { isPostsList = false } ) { 'edit-site-editor__loading-progress' ); - const settings = useSpecificEditorSettings( - !! context?.postId && context?.postType !== 'post' - ); + const settings = useSpecificEditorSettings(); const styles = useMemo( () => [ ...settings.styles, From 9068ab10786095bd2050e51839d5d5022b887616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Tue, 19 Nov 2024 15:14:58 +0100 Subject: [PATCH 42/44] =?UTF-8?q?fix=20clean=20up=20performance=20tests=20?= =?UTF-8?q?by=20moving=20rendering=20mode=20change=20into=20it=E2=80=99s?= =?UTF-8?q?=20own=20helper=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/performance/fixtures/perf-utils.ts | 35 ++++++++++++++-------- test/performance/specs/post-editor.spec.js | 5 ++++ test/performance/specs/site-editor.spec.js | 2 ++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/test/performance/fixtures/perf-utils.ts b/test/performance/fixtures/perf-utils.ts index 6766411e8ff32..02e506b5a45fc 100644 --- a/test/performance/fixtures/perf-utils.ts +++ b/test/performance/fixtures/perf-utils.ts @@ -97,6 +97,29 @@ export class PerfUtils { return canvas; } + /** + * Enters the post-only rendering mode. + * + * This is sometimes needed when for example we want to update the contents + * of the editor from a HTML file. Calling the resetBlocks method of the + * core/block-editor store will replace the contents of the template if the + * rendering mode is not post-only. So this should always be called before + * the resetBlocks method is used. + */ + async enterPostOnlyRenderingMode() { + const initialRenderingMode = await this.page.evaluate( () => { + const { select } = window.wp.data; + return select( 'core/editor' ).getRenderingMode(); + } ); + + if ( initialRenderingMode !== 'post-only' ) { + await this.page.evaluate( () => { + const { dispatch } = window.wp.data; + dispatch( 'core/editor' ).setRenderingMode( 'post-only' ); + } ); + } + } + /** * Loads blocks from the small post with containers fixture into the editor * canvas. @@ -133,18 +156,6 @@ export class PerfUtils { () => window?.wp?.blocks && window?.wp?.data ); - const initialRenderingMode = await this.page.evaluate( () => { - const { select } = window.wp.data; - return select( 'core/editor' ).getRenderingMode(); - } ); - - if ( initialRenderingMode !== 'post-only' ) { - await this.page.evaluate( () => { - const { dispatch } = window.wp.data; - dispatch( 'core/editor' ).setRenderingMode( 'post-only' ); - } ); - } - return await this.page.evaluate( ( html: string ) => { const { parse } = window.wp.blocks; const { dispatch } = window.wp.data; diff --git a/test/performance/specs/post-editor.spec.js b/test/performance/specs/post-editor.spec.js index 85d334749f6f5..292e5c4922ccc 100644 --- a/test/performance/specs/post-editor.spec.js +++ b/test/performance/specs/post-editor.spec.js @@ -55,6 +55,7 @@ test.describe( 'Post Editor Performance', () => { test( 'Setup the test post', async ( { admin, perfUtils } ) => { await admin.createNewPost(); + await perfUtils.enterPostOnlyRenderingMode(); await perfUtils.loadBlocksForLargePost(); draftId = await perfUtils.saveDraft(); } ); @@ -142,6 +143,7 @@ test.describe( 'Post Editor Performance', () => { test( 'Setup the test post', async ( { admin, perfUtils, editor } ) => { await admin.createNewPost(); + await perfUtils.enterPostOnlyRenderingMode(); await perfUtils.loadBlocksForLargePost(); await editor.insertBlock( { name: 'core/paragraph' } ); draftId = await perfUtils.saveDraft(); @@ -165,6 +167,7 @@ test.describe( 'Post Editor Performance', () => { test( 'Setup the test post', async ( { admin, perfUtils, editor } ) => { await admin.createNewPost(); + await perfUtils.enterPostOnlyRenderingMode(); await perfUtils.loadBlocksForLargePost(); await editor.insertBlock( { name: 'core/paragraph' } ); draftId = await perfUtils.saveDraft(); @@ -201,6 +204,7 @@ test.describe( 'Post Editor Performance', () => { test( 'Setup the test post', async ( { admin, perfUtils, editor } ) => { await admin.createNewPost(); + await perfUtils.enterPostOnlyRenderingMode(); await perfUtils.loadBlocksForLargePost(); await editor.insertBlock( { name: 'core/paragraph' } ); draftId = await perfUtils.saveDraft(); @@ -234,6 +238,7 @@ test.describe( 'Post Editor Performance', () => { test( 'Set up the test post', async ( { admin, perfUtils } ) => { await admin.createNewPost(); + await perfUtils.enterPostOnlyRenderingMode(); await perfUtils.loadBlocksForSmallPostWithContainers(); draftId = await perfUtils.saveDraft(); } ); diff --git a/test/performance/specs/site-editor.spec.js b/test/performance/specs/site-editor.spec.js index 9c9d8aec71da4..5ecd2710f29c4 100644 --- a/test/performance/specs/site-editor.spec.js +++ b/test/performance/specs/site-editor.spec.js @@ -64,6 +64,7 @@ test.describe( 'Site Editor Performance', () => { test( 'Setup the test page', async ( { admin, perfUtils } ) => { await admin.createNewPost( { postType: 'page' } ); + await perfUtils.enterPostOnlyRenderingMode(); await perfUtils.loadBlocksForLargePost(); draftId = await perfUtils.saveDraft(); @@ -122,6 +123,7 @@ test.describe( 'Site Editor Performance', () => { test( 'Setup the test post', async ( { admin, editor, perfUtils } ) => { await admin.createNewPost( { postType: 'page' } ); + await perfUtils.enterPostOnlyRenderingMode(); await perfUtils.loadBlocksForLargePost(); await editor.insertBlock( { name: 'core/paragraph' } ); From 4512fce47e0f424c97c5bc4d54d0cc659ac4de9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Tue, 19 Nov 2024 15:50:42 +0100 Subject: [PATCH 43/44] simplify performance tests for rendering mode --- test/performance/fixtures/perf-utils.ts | 33 ++++++++++------------ test/performance/specs/post-editor.spec.js | 5 ---- test/performance/specs/site-editor.spec.js | 4 +-- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/test/performance/fixtures/perf-utils.ts b/test/performance/fixtures/perf-utils.ts index 02e506b5a45fc..8d23d91ff91bf 100644 --- a/test/performance/fixtures/perf-utils.ts +++ b/test/performance/fixtures/perf-utils.ts @@ -98,26 +98,23 @@ export class PerfUtils { } /** - * Enters the post-only rendering mode. + * Change the rendering mode of the editor. * - * This is sometimes needed when for example we want to update the contents - * of the editor from a HTML file. Calling the resetBlocks method of the - * core/block-editor store will replace the contents of the template if the - * rendering mode is not post-only. So this should always be called before - * the resetBlocks method is used. + * Setting the rendering mode to something other than the default is sometimes + * needed when for example we want to update the contents of the editor from a + * HTML file. Calling the resetBlocks method of the core/block-editor store will + * replace the contents of the template if the rendering mode is not post-only. + * So this should always be called before the resetBlocks method is used. + * + * @param newRenderingMode Rendering mode to set + * + * @return Promise */ - async enterPostOnlyRenderingMode() { - const initialRenderingMode = await this.page.evaluate( () => { - const { select } = window.wp.data; - return select( 'core/editor' ).getRenderingMode(); - } ); - - if ( initialRenderingMode !== 'post-only' ) { - await this.page.evaluate( () => { - const { dispatch } = window.wp.data; - dispatch( 'core/editor' ).setRenderingMode( 'post-only' ); - } ); - } + async setRenderingMode( newRenderingMode: string ) { + await this.page.evaluate( ( _newRenderingMode ) => { + const { dispatch } = window.wp.data; + dispatch( 'core/editor' ).setRenderingMode( _newRenderingMode ); + }, newRenderingMode ); } /** diff --git a/test/performance/specs/post-editor.spec.js b/test/performance/specs/post-editor.spec.js index 292e5c4922ccc..85d334749f6f5 100644 --- a/test/performance/specs/post-editor.spec.js +++ b/test/performance/specs/post-editor.spec.js @@ -55,7 +55,6 @@ test.describe( 'Post Editor Performance', () => { test( 'Setup the test post', async ( { admin, perfUtils } ) => { await admin.createNewPost(); - await perfUtils.enterPostOnlyRenderingMode(); await perfUtils.loadBlocksForLargePost(); draftId = await perfUtils.saveDraft(); } ); @@ -143,7 +142,6 @@ test.describe( 'Post Editor Performance', () => { test( 'Setup the test post', async ( { admin, perfUtils, editor } ) => { await admin.createNewPost(); - await perfUtils.enterPostOnlyRenderingMode(); await perfUtils.loadBlocksForLargePost(); await editor.insertBlock( { name: 'core/paragraph' } ); draftId = await perfUtils.saveDraft(); @@ -167,7 +165,6 @@ test.describe( 'Post Editor Performance', () => { test( 'Setup the test post', async ( { admin, perfUtils, editor } ) => { await admin.createNewPost(); - await perfUtils.enterPostOnlyRenderingMode(); await perfUtils.loadBlocksForLargePost(); await editor.insertBlock( { name: 'core/paragraph' } ); draftId = await perfUtils.saveDraft(); @@ -204,7 +201,6 @@ test.describe( 'Post Editor Performance', () => { test( 'Setup the test post', async ( { admin, perfUtils, editor } ) => { await admin.createNewPost(); - await perfUtils.enterPostOnlyRenderingMode(); await perfUtils.loadBlocksForLargePost(); await editor.insertBlock( { name: 'core/paragraph' } ); draftId = await perfUtils.saveDraft(); @@ -238,7 +234,6 @@ test.describe( 'Post Editor Performance', () => { test( 'Set up the test post', async ( { admin, perfUtils } ) => { await admin.createNewPost(); - await perfUtils.enterPostOnlyRenderingMode(); await perfUtils.loadBlocksForSmallPostWithContainers(); draftId = await perfUtils.saveDraft(); } ); diff --git a/test/performance/specs/site-editor.spec.js b/test/performance/specs/site-editor.spec.js index 5ecd2710f29c4..e72d83fa8b3aa 100644 --- a/test/performance/specs/site-editor.spec.js +++ b/test/performance/specs/site-editor.spec.js @@ -64,7 +64,7 @@ test.describe( 'Site Editor Performance', () => { test( 'Setup the test page', async ( { admin, perfUtils } ) => { await admin.createNewPost( { postType: 'page' } ); - await perfUtils.enterPostOnlyRenderingMode(); + await perfUtils.setRenderingMode( 'post-only' ); await perfUtils.loadBlocksForLargePost(); draftId = await perfUtils.saveDraft(); @@ -123,7 +123,7 @@ test.describe( 'Site Editor Performance', () => { test( 'Setup the test post', async ( { admin, editor, perfUtils } ) => { await admin.createNewPost( { postType: 'page' } ); - await perfUtils.enterPostOnlyRenderingMode(); + await perfUtils.setRenderingMode( 'post-only' ); await perfUtils.loadBlocksForLargePost(); await editor.insertBlock( { name: 'core/paragraph' } ); From f282a47a81086776bcb0e1875a8fa8e8fa6ba10c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Tue, 19 Nov 2024 15:58:25 +0100 Subject: [PATCH 44/44] fix move backport file to correct folder --- backport-changelog/{6.7 => 6.8}/7129.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename backport-changelog/{6.7 => 6.8}/7129.md (100%) diff --git a/backport-changelog/6.7/7129.md b/backport-changelog/6.8/7129.md similarity index 100% rename from backport-changelog/6.7/7129.md rename to backport-changelog/6.8/7129.md