gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Add anchor support for dynamic blocks

Open Soean opened this issue 2 years ago • 11 comments

What?

  • Adds anchor support to dynamic rendered blocks.
  • Enables support for core blocks

Fixes #29401

Testing Instructions

You need to add 'id' to $attributes_to_merge in get_block_wrapper_attributes() from the WP_Block_Supports class, see https://github.com/WordPress/wordpress-develop/blob/6.0.2/src/wp-includes/class-wp-block-supports.php#L178

$attributes_to_merge = array( 'style', 'class' );

Change to:

$attributes_to_merge = array( 'style', 'class', 'id' );

Soean avatar Oct 07 '22 08:10 Soean

Yes! I have been waiting for this for so long!

cr0ybot avatar Oct 07 '22 21:10 cr0ybot

I'm very eager to get this merged! Nice work @Soean! 👏

You need to add 'id' to $attributes_to_merge in get_block_wrapper_attributes() from the WP_Block_Supports class, see https://github.com/WordPress/wordpress-develop/blob/6.0.2/src/wp-includes/class-wp-block-supports.php#L178

Could you create a ticket for this in WordPress Core Trac so that a relevant change can be made there?

There's also a small merge conflict in the docs I see 🙂

michalczaplinski avatar Oct 18 '22 17:10 michalczaplinski

@michalczaplinski I created a trac ticket and PR:

  • https://core.trac.wordpress.org/ticket/56852
  • https://github.com/WordPress/wordpress-develop/pull/3497

I also solved the merge conflict.

Soean avatar Oct 19 '22 13:10 Soean

Just tested this PR using a Social Link block, and it works great. For others testing, note that you need to manually apply the patch in https://github.com/WordPress/wordpress-develop/pull/3497.

Editor: image

Front end: image

ndiego avatar Jan 30 '23 22:01 ndiego

Would it be possible to make the anchor block support enabled by default for all blocks?

carolinan avatar Jan 31 '23 06:01 carolinan

Flaky tests detected in 291cced2e2cc5289f06f32e2c3bb6d1e4fc944ca. 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/4053938383 📝 Reported issues:

  • #35176 in specs/editor/various/autosave.test.js

github-actions[bot] avatar Jan 31 '23 06:01 github-actions[bot]

@ndiego, do you see any errors in the DevTools console when testing this branch, with or without the core patch?

I think failing E2E tests are related to the changes in this PR.

Mamaduka avatar Jan 31 '23 11:01 Mamaduka

@carolinan I am getting fatal errors now with the recent updates. Per @Mamaduka it looks like this PR needs to be updated due to https://github.com/WordPress/gutenberg/pull/47195.

ndiego avatar Jan 31 '23 13:01 ndiego

After updating to wp_should_skip_block_supports_serialization I am still seeing this console warning in the editor: traverse.js:26 Error while traversing the CSS: Error: undefined:1:10: missing '{'

Update: Ignore that ^, it was theme related.

carolinan avatar Jan 31 '23 13:01 carolinan

I just retested and everything is looking good on my end.

ndiego avatar Jan 31 '23 13:01 ndiego

Thanks for testing, what do we need to get it merged?

Soean avatar Jan 31 '23 16:01 Soean

Thanks @Mamaduka. I synced the changes to the PR https://github.com/WordPress/wordpress-develop/pull/3497, updated the trac ticket and added it to the tracking issue.

Soean avatar Feb 03 '23 10:02 Soean

Thank you, @Soean!

Mamaduka avatar Feb 03 '23 11:02 Mamaduka

@Soean I added the Needs Dev Note label to this PR. Do you have time to write something up for it in the next few weeks (Deadline is March 3rd :) )

If not I can help with writing something up. :)

fabiankaegy avatar Feb 06 '23 09:02 fabiankaegy

I fear that this change may affect the backward compatibility of some blocks with the anchor. Please see #48232.

t-hamano avatar Feb 19 '23 08:02 t-hamano

I fear that this change may affect the backward compatibility of some blocks with the anchor. Please see #48232.

We've been building pages for wordpress.org and seeing blocks with existing anchors becoming unrecoverable. Typically Group blocks.

adamwoodnz avatar Feb 22 '23 00:02 adamwoodnz

@fabiankaegy and @Soean Are either of you working the dev note for this PR?

  • Does it warrant a stand-alone post? If yes, please post a draft to the Make Core Blog.
  • If you only would write a paragraph or two, comment on this PR, and I'll add it to the Misc Editor Note.

If you could do write this by Thursday (March 2 EOB), that would be helpful. The release squad for 6.2 documentation, will start working on the Field guide for 6.2 on Friday.

bph avatar Feb 28 '23 09:02 bph

@bph In this PR, we found a backward compatibility issue where blocks with anchors were broken, as reported in #47771. We are still discussing #48438 to fix this issue and how it should be addressed.

t-hamano avatar Feb 28 '23 10:02 t-hamano

@bph This change will be reverted in #48592 due to backward compatibility issues as reported in #48232. Here is the discussion on Slack. Therefore, I think Dev Note isn't necessary.

t-hamano avatar Mar 01 '23 01:03 t-hamano