Interactivity Router: Add allowlist system for selective module loading #70890
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #70873
Implements an allowlist-based filtering system for the Interactivity API Router to only load JavaScript modules of interactive blocks during client-side navigation.
Changes:
The solution prevents loading unnecessary JavaScript modules, improving performance and preventing potential conflicts during navigation.
What?
Closes #70873
This PR implements a selective module loading system for the Interactivity API Router that only loads JavaScript modules belonging to interactive blocks during client-side navigation, instead of loading all script modules found in the HTML.
Why?
The current implementation of the Interactivity API Router loads ALL JavaScript modules from the HTML during client-side navigation, including potentially unnecessary ones that aren't related to interactive blocks or compatible with the Interactivity API. This causes:
How?
The solution implements a multi-layered filtering approach:
@wordpress/block-library/*/view
,@wordpress/interactivity*
gutenberg_interactive_module_allowlist
allows plugins to register their interactive modulesKey changes:
preloadScriptModules()
inscript-modules.ts
to filter modules throughisInteractiveBlockModule()
client-assets.php
for server-side allowlist generationTesting Instructions
Manual Testing:
Plugin Developer Testing:
This change doesn't affect the user interface directly - it's a performance optimization for module loading during navigation. Keyboard navigation should work exactly the same as before, but with improved performance. Test by:
Use keyboard navigation (Tab, Enter, Arrow keys) to navigate through interactive blocks
Navigate between pages using keyboard shortcuts
Verify all interactive functionality remains accessible via keyboard