Conversation
513bdc8 to
5e1134c
Compare
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
`WP_Interactivity_API::add_hooks()` registered its filters as `array( $this, 'method' )`, and `data_wp_router_region_processor()` added `array( $this, 'print_router_markup' )` on `wp_footer`. Those callbacks stay bound to the object that was the global when the hooks were added. Replacing the `$wp_interactivity` global later redirects `wp_interactivity_state()` and `wp_interactivity_config()` to the new instance, but the bound callbacks still read the old one, so the printed script module data comes from the wrong instance. Register procedural functions that delegate to the current global instance, matching how classic scripts and styles register their hooks. See #66100, #64484.
5e1134c to
5fb6a39
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Ping @DAreRodz for review. |
…nction. `wp_interactivity_print_router_markup()` returns no value and declared no return type. Declare `: void`. `wp_interactivity_script_module_data()` and `wp_interactivity_router_script_module_data()` already declare `array $data): array`. `wp_interactivity_script_module_attributes()` stays untyped to match `WP_Interactivity_API::add_load_on_client_navigation_attribute_to_script_modules()`, which declares neither a parameter nor a return type. See #66100.
|
|
||
| // Adds the necessary markup to the footer. | ||
| add_action( 'wp_footer', array( $this, 'print_router_markup' ) ); | ||
| add_action( 'wp_footer', 'wp_interactivity_print_router_markup' ); |
There was a problem hiding this comment.
I'm not seeing any back-compat concerns in Veloria: https://veloria.dev/search/307012ac-d787-481a-97ff-1deba5b3122c
| add_filter( 'script_module_data_@wordpress/interactivity-router', array( $this, 'filter_script_module_interactivity_router_data' ) ); | ||
| add_filter( 'wp_script_attributes', array( $this, 'add_load_on_client_navigation_attribute_to_script_modules' ) ); | ||
| add_filter( 'script_module_data_@wordpress/interactivity', 'wp_interactivity_script_module_data' ); | ||
| add_filter( 'script_module_data_@wordpress/interactivity-router', 'wp_interactivity_router_script_module_data' ); |
There was a problem hiding this comment.
I found a back-compat issue here: https://veloria.dev/search/c9034d84-ca18-42eb-a22f-229f6b6fc072
It's in Gutenberg:
Same problem as #13509 for
WP_Interactivity_API:add_hooks()anddata_wp_router_region_processor()bind callbacks to the instance. After the global is replaced,wp_interactivity_state()writes to the new instance and the filters read the old one.This adds four procedural functions to
interactivity-api.phpand registers those instead. Hook names, priorities, and the instance methods are unchanged.Test: replace the global, set state, apply
script_module_data_@wordpress/interactivity. Fails on trunk with empty data. The test file'sset_up()now installs its instance as the global; it registered hooks on an instance that was never the global.Compatibility: Gutenberg
lib/interactivity-api.phpchecks this filter by instance withhas_filter()and will add its own filter too. Both set the same strings, so output is unchanged. That shim should be updated or removed.Trac ticket: https://core.trac.wordpress.org/ticket/66100
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Fable 5.1, Claude Opus
Used for: code, test, description.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
🤖 Generated with Claude Code