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: Add block supports for clientNavigation and interactive properties on block.json schema. #58132

Merged
merged 25 commits into from
Feb 2, 2024

Conversation

cbravobernal
Copy link
Contributor

@cbravobernal cbravobernal commented Jan 23, 2024

What?

Add clientNavigation and interactive properties to block.json schema.

Why?

When the Interactivity API is public, developers will need to indicate if their blocks are client side navigation compatible and interactive in their respective block.json files.

Client navigation will be opt out. Developers will need to set it as true if they want their block to work in client side navigation. (This means there is no interactivity or the block uses the Interactivity API to add interactions).

Testing Instructions

  • Point the schema to block.json schema instead of the default one.
  • Create an interactive block.
  • Check that schemas appear on the editor.
  • Set your block to clientNavigation as true, put it inside a query block and disable "force reload". Check that client side navigation happens (browser does not reload).
  • Set your block to clientNavigation as false, put it inside a query block and disable "force reload". Check that client side navigation does not happen (browser reloads).

@cbravobernal cbravobernal self-assigned this Jan 23, 2024
@cbravobernal cbravobernal added [Packages] Interactivity /packages/interactivity [Type] Enhancement A suggestion for improvement. labels Jan 23, 2024
Copy link

github-actions bot commented Jan 23, 2024

This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress.

If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged.

If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack.

Thank you! ❤️

View changed files
❔ lib/compat/wordpress-6.5/interactivity-api/interactivity-api.php
❔ phpunit/blocks/render-query-test.php

Copy link

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

@luisherranz luisherranz added the [Feature] Interactivity API API to add frontend interactivity to blocks. label Jan 24, 2024
@cbravobernal cbravobernal force-pushed the add/interactivity-block-supports branch from d2570a8 to 1269359 Compare January 31, 2024 17:39
@cbravobernal cbravobernal marked this pull request as ready for review February 1, 2024 15:36
@cbravobernal cbravobernal marked this pull request as draft February 1, 2024 15:37
@cbravobernal cbravobernal marked this pull request as ready for review February 1, 2024 16:12
Comment on lines 144 to 146
$is_interactive_bool = isset( $block_object->supports['interactivity'] ) && true === $block_object->supports['interactivity'];
$is_interactive_object = isset( $block_object->supports['interactivity']['interactive'] ) && true === $block_object->supports['interactivity']['interactive'];
$client_navigation = isset( $block_object->supports['interactivity']['clientNavigation'] ) && true === $block_object->supports['interactivity']['clientNavigation'];
Copy link
Contributor Author

@cbravobernal cbravobernal Feb 1, 2024

Choose a reason for hiding this comment

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

This is PHP 5.6 compatible.

This change would not work in < 7.0 :

	$is_interactive_bool   = (bool) ( $block_object->supports['interactivity'] ?? false );
	$is_interactive_object = (bool) ( $block_object->supports['interactivity']['interactive'] ?? false );
	$client_navigation     = (bool) ( $block_object->supports['interactivity']['clientNavigation'] ?? false );

Copy link
Member

Choose a reason for hiding this comment

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

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.

I haven't checked the code of the Query block yet, so this is just preliminary.

packages/block-library/src/file/block.json Outdated Show resolved Hide resolved
packages/block-library/src/form-input/block.json Outdated Show resolved Hide resolved
packages/block-library/src/form-submit-button/block.json Outdated Show resolved Hide resolved
packages/block-library/src/freeform/block.json Outdated Show resolved Hide resolved
packages/block-library/src/image/block.json Outdated Show resolved Hide resolved
packages/block-library/src/search/block.json Outdated Show resolved Hide resolved
packages/block-library/src/shortcode/block.json Outdated Show resolved Hide resolved
"properties": {
"clientNavigation": {
"type": "boolean",
"description": "Indicates if a block is compatible with Interactivity API client side navigation.\n\nSet as false if the block is using vanilla JS or another framework to handle interactions.",
Copy link
Member

@luisherranz luisherranz Feb 1, 2024

Choose a reason for hiding this comment

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

Suggested change
"description": "Indicates if a block is compatible with Interactivity API client side navigation.\n\nSet as false if the block is using vanilla JS or another framework to handle interactions.",
"description": "Indicates whether a block is compatible with the Interactivity API client-side navigation.\n\nSet it to true only if the block is not interactive or if it is interactive using the Interactivity API. Set it to false if the block is interactive but uses vanilla JS, jQuery or another JS framework/library other than the Interactivity API.",

Copy link
Member

Choose a reason for hiding this comment

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

We could get help from a native speaker here. This is complex to understand 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Tricky 🙂 I've read the descriptions and have questions:

interactivity: boolean|object - What does true mean here? Enable all the features?

true === { clientNavigation: true, interactive: true }
(omission) === false === {}

Should we include the default value for interactivity (which I think is false)?

Can we have clientNavigation without interactive, or does clientNavigation require interactive (if they're dependent we can reflect that in the schema itself instead of describing it).


What does "interactive" mean here?

Set it to true only if the block is not interactive or if it is interactive using the Interactivity API
Set it to false if the block is interactive but uses vanilla JS… other than the Interactivity API

Interactive sounds like interactivity.interactive, but are we talking about that? Or more generally that a block has client-side JavaScript to make it do things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

interactivity: boolean|object - What does true mean here? Enable all the features?

Yes

(omission) === false === {}

I think in this case would be:

{
  clientNavigation: false,
  interactive: false
}

Should we include the default value for interactivity (which I think is false)?

Sure, done.

Interactive sounds like interactivity.interactive, but are we talking about that? Or more generally that a block has client-side JavaScript to make it do things.

Interactive means that a block is using the Interactivity API as alternative of JavaScript made things.

If the developer is using JS or other framework. clientNavigation should be false. interactive in this case would not affect anything on the code. And for that, reason, all options are opt-out. (usually in this case, the user will not update or know about this value)

Copy link

github-actions bot commented Feb 1, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core SVN

If you're a Core Committer, use this list when committing to wordpress-develop in SVN:

Props: cbravobernal, luisherranz, jonsurrell.

GitHub Merge commits

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: c4rl0sbr4v0 <cbravobernal@git.wordpress.org>
Co-authored-by: luisherranz <luisherranz@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@cbravobernal cbravobernal force-pushed the add/interactivity-block-supports branch from 1f1d482 to 36d9491 Compare February 2, 2024 18:57
@cbravobernal cbravobernal merged commit f6e9fcc into trunk Feb 2, 2024
56 checks passed
@cbravobernal cbravobernal deleted the add/interactivity-block-supports branch February 2, 2024 20:24
@github-actions github-actions bot added this to the Gutenberg 17.7 milestone Feb 2, 2024
luisherranz added a commit to luisherranz/wordpress-develop that referenced this pull request Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Interactivity API API to add frontend interactivity to blocks. [Packages] Interactivity /packages/interactivity [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants