-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
base: trunk
Are you sure you want to change the base?
Conversation
Size Change: +2 B (0%) Total Size: 1.91 MB
ℹ️ View Unchanged
|
@@ -91,7 +86,7 @@ function BlockEditAnchorControlPure( { anchor, setAttributes } ) { | |||
onChange={ ( nextValue ) => { | |||
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.
@@ -14,7 +14,7 @@ export function createListBlockFromDOMElement( listElement ) { | |||
const type = listElement.getAttribute( 'type' ); | |||
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. |
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. |
What?
This PR does two things to enable dynamic blocks to support the
anchor
attribute in the future:anchor
attributes 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?
applyBuiltInValidationFixes
for built-in validation fixes. This function contains the code to migrate the previousclassName
andariaLabel
support 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
trunk
branch 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: