Skip to content
Closed
3 changes: 2 additions & 1 deletion backport-changelog/6.9/10324.md
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this file can actually be deleted entirely now?

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
https://github.com/WordPress/wordpress-develop/pull/10324

* https://github.com/WordPress/gutenberg/pull/72340
* https://github.com/WordPress/gutenberg/pull/72340
* https://github.com/WordPress/gutenberg/pull/72449
29 changes: 17 additions & 12 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ function gutenberg_default_script_modules() {
* Access the shared static variable for interactive script modules.
*
* @param string|null $script_module_id The script module ID to register, or null to get the list.
* @return array Associative array of script module ID => true.
* @return array<string, true> Associative array of script module ID => true.
*/
function gutenberg_interactive_script_modules_registry( $script_module_id = null ) {
static $interactive_script_modules = array();
Expand All @@ -735,7 +735,7 @@ function gutenberg_register_interactive_script_module_id( $script_module_id ) {
/**
* Get the list of interactive script module IDs.
*
* @return array Associative array of script module ID => true.
* @return array<string, true> Associative array of script module ID => true.
*/
function gutenberg_get_interactive_script_module_ids() {
return gutenberg_interactive_script_modules_registry();
Expand All @@ -744,18 +744,23 @@ function gutenberg_get_interactive_script_module_ids() {
/**
* Adds `data-wp-router-options` attribute to script modules registered as interactive.
*
* @param array $args The script module attributes.
* @param string $id The script module ID.
* @return array Filtered script module attributes.
* @param array<string, string|true>|mixed $attributes Script attributes.
* @return array<string, string|true> Filtered script attributes.
*/
function gutenberg_script_module_add_router_options_attributes( $args, $id ) {
// Check if this script module ID is registered as interactive.
$interactive_modules = gutenberg_get_interactive_script_module_ids();
function gutenberg_script_module_add_router_options_attributes( $attributes ): array {
if ( ! is_array( $attributes ) ) {
$attributes = array();
}

if ( isset( $interactive_modules[ $id ] ) ) {
$args['data-wp-router-options'] = '{ "loadOnClientNavigation": true }';
if (
isset( $attributes['id'], $attributes['type'] ) &&
'module' === $attributes['type'] &&
1 === preg_match( '/^(.+)-js-module$/', $attributes['id'], $matches ) &&
array_key_exists( $matches[1], gutenberg_get_interactive_script_module_ids() )
) {
$attributes['data-wp-router-options'] = wp_json_encode( array( 'loadOnClientNavigation' => true ) );
}
return $args;
return $attributes;
}

add_filter( 'wp_script_module_attributes', 'gutenberg_script_module_add_router_options_attributes', 10, 2 );
add_filter( 'wp_script_attributes', 'gutenberg_script_module_add_router_options_attributes' );
91 changes: 0 additions & 91 deletions lib/compat/wordpress-6.9/script-modules.php

This file was deleted.

1 change: 0 additions & 1 deletion lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-6.9/customizer-preview-custom-css.php';
require __DIR__ . '/compat/wordpress-6.9/command-palette.php';
require __DIR__ . '/compat/wordpress-6.9/preload.php';
require __DIR__ . '/compat/wordpress-6.9/script-modules.php';

// WordPress 7.0 compat.
require __DIR__ . '/compat/wordpress-7.0/php-only-blocks.php';
Expand Down
Loading