-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Interactivity API runtime (#49994)
* Add interactivity runtime Co-authored-by: David Arenas <david.arenas@automattic.com> * Add it to the image block This is still pretty basic, just to check that it works. Co-authored-by: David Arenas <david.arenas@automattic.com> * Add a separate webpack config Co-authored-by: David Arenas <david.arenas@automattic.com> * Make sure the runtime is imported only once Co-authored-by: David Arenas <david.arenas@automattic.com> * Use sideEffects instead of init Co-authored-by: David Arenas <david.arenas@automattic.com> * Move script registration to a general file Co-authored-by: David Arenas <david.arenas@automattic.com> * Add `defer` to the interactivity scripts Co-authored-by: David Arenas <david.arenas@automattic.com> * Revert changes of the image block Co-authored-by: David Arenas <david.arenas@automattic.com> * Fix init import name Co-authored-by: David Arenas <david.arenas@automattic.com> * Move and refactor the interactive scritps registration * Fix code style violations * Use `wp-interactivity-` prefix for script handles * Improve the matcher for side effects in `package.json` * Add custom useSignalEffect * Call `init` after `store` has been initialized * Update lib/experimental/interactivity-api/script-loader.php Co-authored-by: Weston Ruter <westonruter@google.com> * Plugin: Ensure that translations are set correctly when overriding scripts This replicates the same logic in WordPress core: https://github.com/WordPress/wordpress-develop/blob/a5f3087f6b5d9c52dbe67ed247165dc32427c57d/src/wp-includes/script-loader.php#L306-L308 --------- Co-authored-by: Luis Herranz <luisherranz@gmail.com> Co-authored-by: Grzegorz Ziolkowski <grzegorz@gziolo.pl> Co-authored-by: Weston Ruter <westonruter@google.com>
- Loading branch information
1 parent
cd25a95
commit 9105718
Showing
15 changed files
with
801 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* Updates the script-loader.php file | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Registers interactivity runtime and vendor scripts to use with interactive blocks. | ||
* | ||
* @param WP_Scripts $scripts WP_Scripts instance. | ||
*/ | ||
function gutenberg_register_interactivity_scripts( $scripts ) { | ||
gutenberg_override_script( | ||
$scripts, | ||
'wp-interactivity-runtime', | ||
gutenberg_url( | ||
'build/block-library/interactive-blocks/interactivity.min.js' | ||
), | ||
array( 'wp-interactivity-vendors' ) | ||
); | ||
|
||
gutenberg_override_script( | ||
$scripts, | ||
'wp-interactivity-vendors', | ||
gutenberg_url( | ||
'build/block-library/interactive-blocks/vendors.min.js' | ||
) | ||
); | ||
} | ||
add_action( 'wp_default_scripts', 'gutenberg_register_interactivity_scripts', 10, 1 ); | ||
|
||
/** | ||
* Adds the "defer" attribute to all the interactivity script tags. | ||
* | ||
* @param string $tag The generated script tag. | ||
* @param string $handle The script's registered handle. | ||
* | ||
* @return string The modified script tag. | ||
*/ | ||
function gutenberg_interactivity_scripts_add_defer_attribute( $tag, $handle ) { | ||
if ( str_starts_with( $handle, 'wp-interactivity-' ) ) { | ||
$p = new WP_HTML_Tag_Processor( $tag ); | ||
$p->next_tag( array( 'tag' => 'script' ) ); | ||
$p->set_attribute( 'defer', true ); | ||
return $p->get_updated_html(); | ||
} | ||
return $tag; | ||
} | ||
add_filter( 'script_loader_tag', 'gutenberg_interactivity_scripts_add_defer_attribute', 10, 2 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const directivePrefix = 'data-wp-'; |
Oops, something went wrong.
9105718
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in 9105718.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4892032641
📝 Reported issues:
/test/e2e/specs/editor/blocks/image.spec.js