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 support for __experimentalSkiSerialization to the shadow attribute #6279

Conversation

colinduwe
Copy link

What?
This is a backport of the merged Gutenberg PR WordPress/gutenberg#59887
When a dynamic block defines __experimentalSkipSerialization in its block.supports.shadow the styles continue to be printed to the block wrapper element. This PR corrects that behavior so that shadow behaves like border, color, and others.
Why?
This provides the expected behavior for dynamic blocks that need to opt out of having the shadow styles printed to the block wrapper.
How?
Added a check at the start of the render function to return an empty array if the block has set __experimentalSkipSerialization

(This is my first attempt at submitting a Gutenberg PR to be included back into WP Core so welcome any advice if I'm doing this wrong)

Trac ticket: https://core.trac.wordpress.org/ticket/60784#ticket


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link

github-actions bot commented Mar 15, 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 Committers: Use this line as a base for the props when committing in SVN:

Props colind, madhudollu, aaronrobertshaw, vcanales, isabel_brison.

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

Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

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

Thanks for backporting this fix @colinduwe 👍

The change here matches WordPress/gutenberg#59887.

I was going to note that we should add a unit test for this but it appears no tests have been added for the shadow block support like there are for typography, border etc.

@madhusudhand are you aware of any PRs in progress adding unit tests for the shadow support?

While this does allow support for an experimental block.json property (that should be stabilized soon), it does make the shadow block support consistent with all others while only introducing a call to a stable core function. I'd like to see this land.

@madhusudhand
Copy link
Member

@madhusudhand are you aware of any PRs in progress adding unit tests for the shadow support?

I have created WordPress/gutenberg#60063 which tests these changes.

@vcanales
Copy link
Member

👋 @colinduwe @madhusudhand what is the status here?

It looks like WordPress/gutenberg#60063 has been approved. Are you facing any blockers?

@colinduwe
Copy link
Author

@vcanales I think it is probably only blocked by my ignorance of the process here. I thought this was merely awaiting approval from someone with commit access.

@aaronrobertshaw
Copy link

It looks like WordPress/gutenberg#60063 has been approved. Are you facing any blockers?

Once WordPress/gutenberg#60063 is merged, this should probably also include the unit test the code change relates to.

@madhusudhand
Copy link
Member

@colinduwe could you bring the unit tests from WordPress/gutenberg#60063 into this?

@colinduwe
Copy link
Author

@madhusudhand I think I'm out of my depth here. I'm not sure how to do that.

@madhusudhand
Copy link
Member

@colinduwe I have created #6613 with the unit tests.
Please checkout #6613 to a branch and cherry pick the commit 8a46596 into this PR

git fetch origin pull/6613/head:shadow-unit-tests
git cherry-pick 8a4659608ba43363b4bd63fd76e99635c55141c8

@colinduwe
Copy link
Author

Your're a hero @madhusudhand. Thanks. Done.

Comment on lines 60 to 66
public function test_gutenberg_apply_shadow_support( $support, $value, $expected ) {
$block_type = self::register_shadow_block_with_support(
'test/shadow-block',
array( 'shadow' => $support )
);
$block_attrs = array( 'style' => array( 'shadow' => $value ) );
$actual = gutenberg_apply_shadow_support( $block_type, $block_attrs );
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for bringing in the tests!

We have to rename the functions, since the gutenberg_ prefix is meant to be used within Gutenberg and not core (https://github.com/WordPress/wordpress-develop/pull/6279/files#diff-a903d994435db8240aed96e253cfb2097ecbe9705d6f88ecdfd441422ecf2da3R52)

Suggested change
public function test_gutenberg_apply_shadow_support( $support, $value, $expected ) {
$block_type = self::register_shadow_block_with_support(
'test/shadow-block',
array( 'shadow' => $support )
);
$block_attrs = array( 'style' => array( 'shadow' => $value ) );
$actual = gutenberg_apply_shadow_support( $block_type, $block_attrs );
public function test_wp_apply_shadow_support( $support, $value, $expected ) {
$block_type = self::register_shadow_block_with_support(
'test/shadow-block',
array( 'shadow' => $support )
);
$block_attrs = array( 'style' => array( 'shadow' => $value ) );
$actual = wp_apply_shadow_support( $block_type, $block_attrs );

Copy link
Member

Choose a reason for hiding this comment

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

Fixed here.

@colinduwe please pull and
git cherry-pick 5383012d66abb19d39388750fd3e1b46ec0d60b6

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -52,7 +52,10 @@ function wp_register_shadow_support( $block_type ) {
function wp_apply_shadow_support( $block_type, $block_attributes ) {
$has_shadow_support = block_has_support( $block_type, 'shadow', false );

if ( ! $has_shadow_support ) {
if (
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to add a since note to the docblock above; something like

@since 6.6.0 Return early if __experimentalSkipSerialization is true.

(it should be added just below @since 6.3.0)

Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

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

Thanks for updating @colinduwe, LGTM!

@tellthemachines
Copy link
Contributor

Committed in r58312.

* @param string $value Shadow style value for style attribute object.
* @param array $expected Expected shadow block support styles.
*/
public function test_wp_apply_shadow_support( $support, $value, $expected ) {
Copy link
Member

Choose a reason for hiding this comment

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

@tellthemachines why the ticket number is not mention for test?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for spotting that! Fixed in https://core.trac.wordpress.org/changeset/58315.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants