Interactivity API: Do not process directives when there aren’t any.

Short-circuits directive processing when the markup does not actually contain any `data-wp-*` attributes.
This reduces function calls and memory usage for the best case scenario due to not involving `WP_HTML_Tag_Processor`.

Props joemcgill, swissspidy, gziolo, cbravobernal, flixos90.
Fixes #60749.
Built from https://develop.svn.wordpress.org/trunk@57824


git-svn-id: http://core.svn.wordpress.org/trunk@57325 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2024-03-13 10:41:14 +00:00
parent 61de23a489
commit 9958729416
2 changed files with 5 additions and 1 deletions

View File

@ -204,6 +204,10 @@ final class WP_Interactivity_API {
* @return string The processed HTML content. It returns the original content when the HTML contains unbalanced tags.
*/
public function process_directives( string $html ): string {
if ( ! str_contains( $html, 'data-wp-' ) ) {
return $html;
}
$context_stack = array();
$namespace_stack = array();
$result = $this->process_directives_args( $html, $context_stack, $namespace_stack );

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.6-alpha-57822';
$wp_version = '6.6-alpha-57824';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.