Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactivity API: Server Directive Processing Refactor #58066

Merged
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
573bfe2
Initial SDP version
luisherranz Jan 16, 2024
a1495fc
Rename `initialState` to `state`
luisherranz Jan 22, 2024
bcefd09
Fix incorrect package
luisherranz Jan 22, 2024
d563a90
Properly remove the SDP during the e2e tests
luisherranz Jan 22, 2024
5535d29
Merge branch 'trunk' into interactivity-api-server-directive-processi…
luisherranz Jan 23, 2024
f94ecc1
Update multiline comments to fit WP standards
cbravobernal Jan 23, 2024
5d68f19
Add @access private to WP_Interactivity_API_Directives_Processor
luisherranz Jan 24, 2024
388cfc0
Merge remote-tracking branch 'origin/interactivity-api-server-directi…
luisherranz Jan 24, 2024
4ca55a5
Remove array check and rename bookmarks in WP_Interactivity_API_Direc…
luisherranz Jan 24, 2024
3425e5d
Dont print config/state if it's empty
luisherranz Jan 24, 2024
fbda36b
Add failing test for </ >
luisherranz Jan 24, 2024
d4f584a
Add missing `object` word
luisherranz Jan 24, 2024
246317a
Missing indentation on ternary conditionals
luisherranz Jan 24, 2024
560a17e
Improve namespace extraction from directive value
luisherranz Jan 24, 2024
8ef546f
Move modified properties to the end in set_style_property
luisherranz Jan 24, 2024
d7e73b5
Replace tabindex comment
luisherranz Jan 24, 2024
56f3747
Remove filter after processing and bump priority
luisherranz Jan 24, 2024
614ef66
Replace own is_void with HTML API one
luisherranz Jan 24, 2024
c45893f
Missing ternary indentation
luisherranz Jan 24, 2024
fab5662
Avoid early returns
luisherranz Jan 24, 2024
5de71d2
Merge branch 'trunk' into interactivity-api-server-directive-processi…
luisherranz Jan 24, 2024
bdd0fad
Update wp_register_script_module function
luisherranz Jan 24, 2024
c3c87d3
Replaces some incorrect docblock comments with block comments
luisherranz Jan 24, 2024
6cee3ba
Fix indent ternaries (again)
luisherranz Jan 24, 2024
6b62b97
Add more info about how extract_directive_value behaves
luisherranz Jan 24, 2024
93eefeb
Add more edge cases
luisherranz Jan 24, 2024
1954f45
Improve wp_interactivity_process_directives_of_interactive_blocks com…
luisherranz Jan 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,40 @@
function wp_interactivity_process_directives_of_interactive_blocks( $parsed_block ) {
static $root_interactive_block = null;

/**
luisherranz marked this conversation as resolved.
Show resolved Hide resolved
* Checks whether a root interactive block is already annotated for
* processing, and if it is, it ignores the subsequent ones.
*/
if ( null === $root_interactive_block ) {
$block_name = $parsed_block['blockName'];
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_name );

if ( isset( $block_name ) && isset( $block_type->supports['interactivity'] ) && $block_type->supports['interactivity'] ) {
// Annotates the root interactive block for processing.
$root_interactive_block = array( $block_name, md5( serialize( $parsed_block ) ) );

$process_interactive_blocks = static function ( $content, $parsed_block ) use ( &$root_interactive_block ) {
/**
* Adds a filter to process the root interactive block once it has
* finished rendering.
*/
$process_interactive_blocks = static function ( $content, $parsed_block ) use ( &$root_interactive_block, &$process_interactive_blocks ) {
// Checks whether the current block is the root interactive block.
list($root_block_name, $root_block_md5) = $root_interactive_block;
if ( $root_block_name === $parsed_block['blockName'] && md5( serialize( $parsed_block ) ) === $root_block_md5 ) {
// The root interactive blocks has finished rendering, process it.
$content = wp_interactivity_process_directives( $content );
// Removes the filter and reset the root interactive block.
remove_filter( 'render_block', $process_interactive_blocks );
$root_interactive_block = null;
$content = wp_interactivity_process_directives( $content );
}
return $content;
};

add_filter( 'render_block', $process_interactive_blocks, 10, 2 );
/**
* Uses a priority of 20 to ensure that other filters can add additional
* directives before the processing starts.
*/
add_filter( 'render_block', $process_interactive_blocks, 20, 2 );
}
}

Expand Down
Loading