-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add Interactivity API runtime #49994
Merged
+801
−139
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5751344
Add interactivity runtime
luisherranz e8201c2
Add it to the image block
luisherranz df844f0
Add a separate webpack config
luisherranz d883391
Make sure the runtime is imported only once
luisherranz b1ea5e3
Use sideEffects instead of init
luisherranz 20d6213
Move script registration to a general file
luisherranz 6fb8aa7
Add `defer` to the interactivity scripts
luisherranz 6c96509
Revert changes of the image block
luisherranz e843b80
Fix init import name
luisherranz cdf74b9
Move and refactor the interactive scritps registration
gziolo de0e874
Fix code style violations
gziolo fa7c00d
Use `wp-interactivity-` prefix for script handles
gziolo 0d88c77
Improve the matcher for side effects in `package.json`
gziolo 142050c
Add custom useSignalEffect
DAreRodz e65b91e
Call `init` after `store` has been initialized
DAreRodz 9a31bb4
Update lib/experimental/interactivity-api/script-loader.php
gziolo 0cdab08
Plugin: Ensure that translations are set correctly when overriding sc…
gziolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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.
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.
Noting that
react
is set as a peer dependency to make integrating with 3rd party projects easier. Would it make sense to follow the same approach forpreact
?