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

Headline Block's auto anchor code is causing duplicate identical element ids #315

Open
acketon opened this issue Oct 13, 2022 · 0 comments · May be fixed by #329
Open

Headline Block's auto anchor code is causing duplicate identical element ids #315

acketon opened this issue Oct 13, 2022 · 0 comments · May be fixed by #329
Assignees
Labels
💡 Bug Fixed in WP 5.7 Branch 🔥 Product bug A bug which is not directly related to a custom child theme.

Comments

@acketon
Copy link
Member

acketon commented Oct 13, 2022

This code:

// Generate an index-based value for the anchor attribute if it is not set.
if ( ! anchor ) {
const headlineBlocks = getBlocks().filter( e => e.name === 'editorial/headline' );
const id = 'headline-' + ( headlineBlocks.length );
setAttributes( { anchor: id } );
}

should be removed as it causes duplicate element id's in a couple scenarios:

  1. The code is only looking at headline blocks that are top level in the tree, it's not seeing headline blocks that are children of other blocks. When they are child blocks the id attribute is incorrect and leads to duplicates which SiteImprove then flags as an level A issue.

  2. When duplicating an existing headline the anchor doesn't change so headline-1 becomes headline-1 on the duplicate block too. Admittedly this is how gutenberg works I think but is still not a great idea.

I'd suggest removing this feature as it isn't used anywhere and let the editor manually set the anchor in the anchor field.

@acketon acketon added 💡 Bug 🔥 Product bug A bug which is not directly related to a custom child theme. labels Oct 13, 2022
@acketon acketon self-assigned this Nov 21, 2022
@acketon acketon linked a pull request Aug 23, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 Bug Fixed in WP 5.7 Branch 🔥 Product bug A bug which is not directly related to a custom child theme.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant