Skip to content

Duplicate heading ids generated for headings repeated 3+ times #46

Description

@vdvman1

parseHeader in src/components/java/patch-notes.tsx de-duplicates generated heading ids, but writes the counter under the already-suffixed id instead of the base id:

let id = toKebabCase(headingText);
const dups = ids.get(id) ?? 0;
if (dups > 0) {
  id += `-${dups}`;
}
ids.set(id, dups + 1);   // <-- `id` has already been reassigned

So the base id's counter never advances past 1:

occurrence dups read id emitted counter written
1st 0 (parameters) parameters parameters → 1
2nd 1 (parameters) parameters-1 parameters-1 → 2
3rd 1 (parameters) parameters-1 parameters-1 → 2

Every occurrence from the third onward collides on -1.

Impact. Duplicate DOM ids, so the table-of-contents anchor links for the affected headings all jump to the same place. Measured across all 403 articles in the v2 manifest: 7 articles emit literally duplicate ids, worst case 1.14, which emits parameters-1 ten times.

Fix. Key the counter on the base id:

const base = toKebabCase(headingText);
const dups = ids.get(base) ?? 0;
const id = dups > 0 ? `${base}-${dups}` : base;
ids.set(base, dups + 1);

Note this still can't guarantee uniqueness against a heading whose literal text is Parameters 1, so consider a uniqueness check on the final id.

Found while researching #36 (annotation anchoring) — heading-derived ids were being evaluated as an anchor selector and rejected partly because of this. Filing separately because it is a live bug in the rendered page today, independent of that work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions