From 12171002ea302bfead964ea1cc0b56fa58ef0488 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 27 Sep 2024 09:58:56 +0200 Subject: [PATCH 1/3] Revert "Revert [59097] because it was renaming a public method that should be deprecated instead." This reverts commit bbec266c74fc47ce2919faa4cf3c6d43044588cb. --- .../class-wp-interactivity-api.php | 53 ++++++++++++------- .../wpInteractivityAPI-wp-router-region.php | 6 +-- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php index 1213a5c097440..e4dec8e262381 100644 --- a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php +++ b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php @@ -199,6 +199,26 @@ public function print_client_interactivity_data() { _deprecated_function( __METHOD__, '6.7.0' ); } + /** + * Set client-side interactivity-router data. + * + * Once in the browser, the state will be parsed and used to hydrate the client-side + * interactivity stores and the configuration will be available using a `getConfig` utility. + * + * @since 6.7.0 + * + * @param array $data Data to filter. + * @return array Data for the Interactivity Router script module. + */ + public function filter_script_module_interactivity_router_data( array $data ): array { + if ( ! isset( $data['i18n'] ) ) { + $data['i18n'] = array(); + } + $data['i18n']['loading'] = __( 'Loading page, please wait.' ); + $data['i18n']['loaded'] = __( 'Page Loaded.' ); + return $data; + } + /** * Set client-side interactivity data. * @@ -296,6 +316,7 @@ public function register_script_modules() { */ public function add_hooks() { add_filter( 'script_module_data_@wordpress/interactivity', array( $this, 'filter_script_module_interactivity_data' ) ); + add_filter( 'script_module_data_@wordpress/interactivity-router', array( $this, 'filter_script_module_interactivity_router_data' ) ); } /** @@ -973,16 +994,14 @@ private function get_router_animation_styles(): string { } /** - * Outputs the markup for the top loading indicator and the screen reader - * notifications during client-side navigations. + * Outputs markup for the @wordpress/interactivity-router script module. * * This method prints a div element representing a loading bar visible during - * navigation, as well as an aria-live region that can be read by screen - * readers to announce navigation status. + * navigation. * - * @since 6.5.0 + * @since 6.7.0 */ - public function print_router_loading_and_screen_reader_markup() { + public function print_router_markup() { echo << -
HTML; } @@ -1016,16 +1029,16 @@ private function data_wp_router_region_processor( WP_Interactivity_API_Directive if ( 'enter' === $mode && ! $this->has_processed_router_region ) { $this->has_processed_router_region = true; - // Initialize the `core/router` store. + /* + * Initialize the `core/router` store. + * If the store is not initialized like this with minimal + * navigation object, the interactivity-router script module + * errors. + */ $this->state( 'core/router', array( - 'navigation' => array( - 'texts' => array( - 'loading' => __( 'Loading page, please wait.' ), - 'loaded' => __( 'Page Loaded.' ), - ), - ), + 'navigation' => new stdClass(), ) ); @@ -1035,7 +1048,7 @@ private function data_wp_router_region_processor( WP_Interactivity_API_Directive wp_enqueue_style( 'wp-interactivity-router-animations' ); // Adds the necessary markup to the footer. - add_action( 'wp_footer', array( $this, 'print_router_loading_and_screen_reader_markup' ) ); + add_action( 'wp_footer', array( $this, 'print_router_markup' ) ); } } diff --git a/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-router-region.php b/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-router-region.php index 8d8cdb6228d2e..d6deab48ab141 100644 --- a/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-router-region.php +++ b/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-router-region.php @@ -102,7 +102,7 @@ public function test_wp_router_region_missing() { * * @covers ::process_directives */ - public function test_wp_router_region_adds_loading_bar_aria_live_region_only_once() { + public function test_wp_router_region_adds_loading_bar_region_only_once() { $html = '
Interactive region
Another interactive region
@@ -125,9 +125,5 @@ public function test_wp_router_region_adds_loading_bar_aria_live_region_only_onc $p = new WP_HTML_Tag_Processor( $footer ); $this->assertTrue( $p->next_tag( $query ) ); $this->assertFalse( $p->next_tag( $query ) ); - $query = array( 'class_name' => 'screen-reader-text' ); - $p = new WP_HTML_Tag_Processor( $footer ); - $this->assertTrue( $p->next_tag( $query ) ); - $this->assertFalse( $p->next_tag( $query ) ); } } From 76f506f6ca73e63a3ca6ebbd29f9cbf1ada1cd17 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 27 Sep 2024 10:10:43 +0200 Subject: [PATCH 2/3] Restore print_router_loading_and_screen_reader_markup method Keep the original method (as a no-op) to avoid possible fatal errors. --- .../interactivity-api/class-wp-interactivity-api.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php index e4dec8e262381..8ffd612b13789 100644 --- a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php +++ b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php @@ -993,6 +993,16 @@ private function get_router_animation_styles(): string { CSS; } + /** + * Deprecated. + * + * @since 6.5.0 + * @deprecated 6.7.0 Use {@see WP_Interactivity_API::print_router_markup} instead. + */ + public function print_router_loading_and_screen_reader_markup() { + _deprecated_function( __METHOD__, '6.7.0', 'WP_Interactivity_API::print_router_markup' ); + } + /** * Outputs markup for the @wordpress/interactivity-router script module. * From e09839e079b75bd32e9bab0aad0502c0ee333886 Mon Sep 17 00:00:00 2001 From: Michal Czaplinski Date: Mon, 30 Sep 2024 13:53:12 +0100 Subject: [PATCH 3/3] Call the new `print_router_markup` method in the deprecated `print_router_loading_and_screen_reader_markup` method --- .../interactivity-api/class-wp-interactivity-api.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php index 8ffd612b13789..022bc082541e0 100644 --- a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php +++ b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php @@ -1001,6 +1001,9 @@ private function get_router_animation_styles(): string { */ public function print_router_loading_and_screen_reader_markup() { _deprecated_function( __METHOD__, '6.7.0', 'WP_Interactivity_API::print_router_markup' ); + + // Call the new method. + $this->print_router_markup(); } /**