-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Block support: Preserve anchor value in comment delimiter #70993
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
Conversation
|
Size Change: +9 B (0%) Total Size: 2.57 MB
ℹ️ View Unchanged
|
| nextValue = nextValue.replace( ANCHOR_REGEX, '-' ); | ||
| setAttributes( { | ||
| anchor: nextValue, | ||
| anchor: nextValue !== '' ? nextValue : undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is necessary to avoid storing an empty string in comment delimiters. Also, without this change, some unit tests would fail.
| const listAttributes = { | ||
| ordered: 'OL' === listElement.tagName, | ||
| anchor: listElement.id === '' ? undefined : listElement.id, | ||
| anchor: listElement.id ? listElement.id : undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without making this change, the mobile unit tests will fail. See: http://github.com/WordPress/gutenberg/actions/runs/16643294936/job/47097872501
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
youknowriad
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me. (Note that I didn't test the PR properly)
|
@youknowriad Thanks for the review! There may be differing opinions on the approach, so I'll leave it open until next week to see if there's any additional feedback. |
|
Flaky tests detected in fb80a2d. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/17676460715
|
|
This PR was discussed in today's 6.9 Bug Scrub: https://wordpress.slack.com/archives/C02RQBWTW/p1760349505009589 @shimotmk said:
Can we ship this PR into 6.9? However, note that this PR only changes the behavior of the anchor support itself; anchor support for dynamic blocks will need to be addressed by a follow-up PR. |
Bump with a pretty please. Thank you for tackling this Aki! |
Mamaduka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @t-hamano!
Let's merge this, this works well in my tests ✅
What?
This PR does two things to enable dynamic blocks to support the
anchorattribute in the future:anchorattributes to always store values as comment delimiters.Why?
My first attempt was to extend the anchor support and allow you to decide whether or not to save an attribute as a comment delimiter (See #48438 (comment)).
However, rather than doing that heavy lifting, I thought it would be best to always store the value in the comment attribute, regardless of how the block is stored, similar to how class names and aliases are supported.
How?
applyBuiltInValidationFixesfor built-in validation fixes. This function contains the code to migrate the previousclassNameandariaLabelsupport to the new schema. I added the migration code for the anchor support here.Note: Dynamic block anchor support doesn't yet work with just this PR. As with aria-label support, some work needs to be done to inject IDs into the rendered HTML. This issue also requires a core backport PR, so I'll address it in #70995 as a follow-up.
Testing Instructions
Check out the
trunkbranch and insert some blocks with IDs:Check out this branch and reload the post. The sblock should not break.
Make changes to the content. The HTML will be updated to look like this: