gutenberg
gutenberg copied to clipboard
Add anchor support for dynamic blocks
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' );
Yes! I have been waiting for this for so long!
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 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.
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:
Front end:
Would it be possible to make the anchor block support enabled by default for all blocks?
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
@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.
@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.
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.
I just retested and everything is looking good on my end.
Thanks for testing, what do we need to get it merged?
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.
Thank you, @Soean!
@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. :)
I fear that this change may affect the backward compatibility of some blocks with the anchor. Please see #48232.
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.
@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 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.
@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.