Skip to content

fix: dedupe heading slugs to prevent duplicate ids on doc pages#1961

Open
sanketssc wants to merge 1 commit intosveltejs:mainfrom
sanketssc:fix/duplicateSlugsMd
Open

fix: dedupe heading slugs to prevent duplicate ids on doc pages#1961
sanketssc wants to merge 1 commit intosveltejs:mainfrom
sanketssc:fix/duplicateSlugsMd

Conversation

@sanketssc
Copy link
Copy Markdown

Fixes #1281

When a module exposes a class and a type with the same name (e.g. the Spring class and the legacy interface Spring<T> in svelte/motion), the generator emits two ## Spring H2s. The renderer assigned both the same id="Spring", which:

  • produced invalid HTML (duplicate ids on the page),
  • broke in-page anchors (/docs/svelte/svelte-motion#Spring only ever reached the first heading, the legacy interface section was unreachable),
  • broke the "On this page" TOC (clicking either Spring link highlighted both at once).

This PR dedupes heading slugs per page. The first occurrence keeps the bare slug, subsequent occurrences get -1, -2, … suffixes. The same dedupe is applied in two places so they stay in sync:

  • packages/site-kit/src/lib/markdown/renderer.ts — heading id + permalink href in rendered HTML.
  • packages/site-kit/src/lib/server/content/index.tssections/subsections metadata that powers OnThisPage.svelte.

Result on /docs/svelte/svelte-motion: first Spring (class) stays at #Spring, legacy interface section becomes #Spring-1. Each TOC entry now activates independently.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time.
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.

Copilot AI review requested due to automatic review settings May 1, 2026 14:55
@vercel
Copy link
Copy Markdown

vercel Bot commented May 1, 2026

@sanketssc is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses duplicate heading id values on docs pages by de-duplicating generated heading slugs per page, keeping rendered heading anchors and the “On this page” TOC metadata aligned.

Changes:

  • Add per-page slug de-duping when generating sections/subsections metadata for the docs TOC.
  • Add per-page slug de-duping when rendering heading id attributes and permalink hrefs in markdown output.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/site-kit/src/lib/server/content/index.ts De-dupes sections and subsections slugs so TOC entries remain unique per page.
packages/site-kit/src/lib/markdown/renderer.ts De-dupes rendered heading ids / permalinks to avoid duplicate IDs in generated HTML.

Comment thread packages/site-kit/src/lib/markdown/renderer.ts Outdated
@sanketssc sanketssc force-pushed the fix/duplicateSlugsMd branch from 51fc9e6 to 8230b60 Compare May 1, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs (Svelte): duplicate element id

2 participants