From b099499881af2eba0a6af31ada2bf90a5409dc12 Mon Sep 17 00:00:00 2001 From: Marcos Caceres Date: Sat, 9 May 2026 14:23:15 +1000 Subject: [PATCH] fix(core/title): detect id="title" collision and use fallback 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 --- src/core/title.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/title.js b/src/core/title.js index 912df79c35..9d2c2b7b4e 100644 --- a/src/core/title.js +++ b/src/core/title.js @@ -51,7 +51,18 @@ export function run(conf) { } // Decorate the spec title - if (!h1Elem.id) h1Elem.id = "title"; + if (!h1Elem.id) { + const existing = document.getElementById("title"); + if (existing && existing !== h1Elem) { + const msg = + 'Another element already uses `id="title"`. ' + + "The spec's `

` will use a different id to avoid a collision."; + showError(msg, name, { elements: [existing] }); + h1Elem.id = "document-title"; + } else { + h1Elem.id = "title"; + } + } h1Elem.classList.add("title"); setDocumentTitle(conf, h1Elem);