fix(core/title): detect id="title" collision and use fallback - #5285
Draft
marcoscaceres wants to merge 3 commits into
Draft
fix(core/title): detect id="title" collision and use fallback#5285marcoscaceres wants to merge 3 commits into
marcoscaceres wants to merge 3 commits into
Conversation
When another element already uses id="title", the spec's h1 now gets id="document-title" instead of silently creating a duplicate ID. An error is shown identifying the conflicting element. Closes #4712
marcoscaceres
commented
Aug 11, 2026
|
|
||
| // Decorate the spec title | ||
| if (!h1Elem.id) h1Elem.id = "title"; | ||
| if (!h1Elem.id) { |
Contributor
Author
There was a problem hiding this comment.
This needs a test. @copilot, can you add a test for this?
Contributor
There was a problem hiding this comment.
Added tests/spec/core/title-spec.js with two tests:
- Verifies that when another element already has
id="title", the<h1>falls back toid="document-title"and acore/titleerror is emitted. - Verifies normal behavior (no collision) —
<h1>keepsid="title"and no error is emitted.
Co-authored-by: marcoscaceres <870154+marcoscaceres@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds title-ID collision handling, but the new path is unreachable and incompatible with existing title consumers.
Changes:
- Detects an existing
id="title". - Reports an error and assigns a fallback ID.
Suppressed comments (2)
src/core/title.js:61
- Assigning the fallback ID breaks downstream title handling. The W3C, AOM, and DINI header templates still locate the title with
document.querySelector("h1#title")(src/w3c/templates/headers.js:249,src/aom/templates/headers.js:51, andsrc/dini/templates/headers.js:115), so a reachable fallback title will not be moved into the document header;src/w3c/level.js:41can also dereferencenull, and the back-to-top link still targets the colliding#title. Update these consumers to locate the generated title independently of its ID and link to its actual ID.
h1Elem.id = "document-title";
src/core/title.js:61
- The fixed fallback is not guaranteed to be free. If the source already contains
id="document-title", this assignment creates another duplicate ID while claiming to avoid a collision. Generate a unique fallback (the existingaddIdhelper already handles occupied IDs) and cover this case in the collision tests.
h1Elem.id = "document-title";
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| // Decorate the spec title | ||
| if (!h1Elem.id) h1Elem.id = "title"; | ||
| if (!h1Elem.id) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4712
When another element already uses id="title", emit an error and
fall back to id="document-title" for the h1.
Written with AI: this change was generated by Claude. Per AI_POLICY.md.