Skip to content

fix(core): add unique heading IDs to Markdown for Outline compatibility#4191

Open
saadpocalypse wants to merge 1 commit into
facebook:mainfrom
saadpocalypse:fix/markdown-heading-ids
Open

fix(core): add unique heading IDs to Markdown for Outline compatibility#4191
saadpocalypse wants to merge 1 commit into
facebook:mainfrom
saadpocalypse:fix/markdown-heading-ids

Conversation

@saadpocalypse

Copy link
Copy Markdown

Description

Outline's documentation states that the id on an outline item should match the target heading element's id. While useOutlineFromMarkdown is provided to derive these outline IDs, the <Markdown> component never rendered id attributes on the headings it produced. As a result, clicking an Outline item changed the location.hash but never scrolled the page because document.getElementById(id) returned null.

This PR fixes the issue by generating unique heading IDs during Markdown rendering to match the output of useOutlineFromMarkdown, and attaches them to the rendered heading tags and components.heading overrides.

Changes

  • Refactored packages/core/src/Outline/parseOutlineFromMarkdown.ts to import helper functions from the parser module, eliminating duplicated code.
  • Exported the inlineText, slugify, and uniqueSlug functions from packages/core/src/Markdown/parser.ts.
  • Updated the MarkdownComponents type interface in packages/core/src/Markdown/Markdown.tsx so custom heading component overrides can accept an optional id.
  • Implemented a headingIdMap memo hook in the <Markdown> component and propagated resolved heading IDs to all rendered header tags and components.
  • Ensured compliance with React's Rules of Hooks by defining the headingIdMap hook above the early-return conditional check for inline display mode.
  • Added a colocated unit test in packages/core/src/Markdown/Markdown.test.tsx to verify headings are rendered with the correct unique ID attributes.

Verification

  • Ran the core package tests using pnpm -F @astryxdesign/core test packages/core/src/Markdown/Markdown.test.tsx --run and verified all 56 tests passed successfully.
  • Confirmed that heading elements are rendered with matching ID attributes, enabling smooth scrolling/hash navigation without custom slug overrides.

Resolves #4173

@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 22, 2026 10:49am

Request Review

@meta-cla

meta-cla Bot commented Jul 22, 2026

Copy link
Copy Markdown

Hi @saadpocalypse!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Jul 22, 2026
@meta-cla

meta-cla Bot commented Jul 22, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Markdown-rendered headings have no id — Outline links never scroll to their target

1 participant