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

Add filter to turn off Interactivity API for a block #52579

Merged
merged 3 commits into from
Jul 13, 2023

Conversation

westonruter
Copy link
Member

What?

Add a gutenberg_should_block_use_interactivity_api filter which allows the experimental Interactivity API to be disabled for a given block.

Why?

This is a follow-up to #52553 for reasons explained in #50906 (comment). Currently the only way to prevent the Interactivity API from being used for the File block or Navigation block is to hack the GUTENBERG_IS_PLUGIN constant to be false. Since the experimental Interactivity API is not behind an experiment feature flag, this filter is needed in order to be able to access and hack on the old implementations.

How?

The gutenberg_should_block_use_interactivity_api filter is added in a function of the same name. This is used in places where the GUTENBERG_IS_PLUGIN constant was used to determine whether to use the Interactivity API.

Testing Instructions

Add a mu-plugin that that includes this code:

add_filter( 'gutenberg_should_block_use_interactivity_api', '__return_false' );

When absent, a post with the File block and Navigation block contain in the footer:

<script src='http://localhost:8888/wp-content/plugins/gutenberg/build/interactivity/index.min.js?ver=1689183370' id='wp-interactivity-js'></script>
<script src='http://localhost:8888/wp-content/plugins/gutenberg/build/block-library/blocks/navigation/view-interactivity.min.js?ver=3dae10865f3f5dd45c1d' id='wp-block-navigation-view-js'></script>
<script src='http://localhost:8888/wp-content/plugins/gutenberg/build/block-library/blocks/file/view-interactivity.min.js?ver=033f781a5a681b19ffeb' id='wp-block-file-view-js'></script>

When present, those scripts do not appear in the footer and instead these scripts appear in the head:

<script src='http://localhost:8888/wp-content/plugins/gutenberg/build/block-library/blocks/navigation/view.min.js?ver=7e248642387235da6fc6' id='wp-block-navigation-view-js'></script>
<script src='http://localhost:8888/wp-content/plugins/gutenberg/build/block-library/blocks/navigation/view-modal.min.js?ver=bc9582176e71f4196e97' id='wp-block-navigation-view-2-js'></script>
<script src='http://localhost:8888/wp-content/plugins/gutenberg/build/block-library/blocks/file/view.min.js?ver=7a5cb419b4808ec7a475' id='wp-block-file-view-js'></script>

Comment on lines +21 to +22
* @since 6.3.0
*
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not be right.

@github-actions
Copy link

github-actions bot commented Jul 12, 2023

Flaky tests detected in 9858855.
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/5545553033
📝 Reported issues:

Copy link
Member

@luisherranz luisherranz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good to me and it works fine. I just added a small suggestion below 👍

lib/experimental/interactivity-api/scripts.php Outdated Show resolved Hide resolved
Copy link
Member

@luisherranz luisherranz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested again and it's working perfectly. Feel free to merge 🙂

Copy link
Contributor

@SantosGuillamot SantosGuillamot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested as well, and everything seems correct 🙂

@westonruter westonruter enabled auto-merge (squash) July 13, 2023 16:28
@westonruter westonruter merged commit b690db2 into trunk Jul 13, 2023
@westonruter westonruter deleted the add/interactivity-api-feature-filter branch July 13, 2023 17:36
@github-actions github-actions bot added this to the Gutenberg 16.3 milestone Jul 13, 2023
westonruter added a commit that referenced this pull request Jul 13, 2023
…dd/defer-script-loading-strategy

* 'trunk' of https://github.com/WordPress/gutenberg: (24 commits)
  Add filter to turn off Interactivity API for a block (#52579)
  Search: Remove unnecessary useEffect (#52604)
  Navigation: Simplify the useSelect for useNavigationMenus (#51977)
  Item: Unify focus style and add default font styles (#52495)
  Update Changelog for 16.2.1
  Bump plugin version to 16.2.1
  Avoid passing undefined `selectedBlockClientId` in `BlockActionsMenu` (#52595)
  Cover Block: Fix block deprecation when fixed background is enabled (#51612)
  Nav block: link text color inheritance fixes and tests (#51710)
  Stabilize defaultBlock, directInsert API's and getDirectInsertBlock selector (#52083)
  Fix console warning by improving error handling in Nav block classic menu conversion (#52591)
  Fix: Remove link action of Link UI for draft pages created from Nav block does not correctly remove link. (#52415)
  Lodash: Remove remaining `_.get()` from block editor and deprecate (#52561)
  Fix importing classic menus (#52573)
  ResizableFrame: Make keyboard accessible (#52443)
  Site Editor: Fix navigation menu sidebar actions order and label (#52592)
  correct a typo: sapce -> space (#52578)
  Avoid errors in Dimension visualizers when switching between iframed and non-iframed editors (#52588)
  Patterns: Add client side pagination to patterns list (#52538)
  Site Editor: Make sidebar back button go *back* instead of *up* if possible (#52456)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] File Affects the File Block [Block] Navigation Affects the Navigation Block [Feature] Interactivity API API to add frontend interactivity to blocks. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants