Repository navigation
fix(core): render heading ids in Markdown so Outline hash links scroll (#4173) - #4765
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
jiunshinn
marked this pull request as ready for review
August 6, 2026 18:02
jiunshinn
requested review from
cixzhang,
ejhammond and
imdreamrunner
as code owners
August 6, 2026 18:02
cixzhang
approved these changes
Aug 19, 2026
cixzhang
left a comment
Contributor
There was a problem hiding this comment.
Thanks for fixing this!
cixzhang
enabled auto-merge (squash)
August 19, 2026 10:46
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsMarkdown (@astryxdesign/core) · View in Storybook
Outline (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 serious. Outline - 1 issue(s)
Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
This branch was successfully deployed
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.
Fixes #4173. Tracked under "Known accessibility bugs" in the accessibility program tracker #4475.
Root cause
Outline documents a contract that Markdown never fulfilled. The
itemsprop docs state the id "should match the target heading DOM id", anduseOutlineFromMarkdownexists specifically to derive that id list from markdown source.parseOutlineFromMarkdownslugifies heading text (inlineText->slugify->uniqueSlug), but the Markdown renderer never wrote anyidattribute onto the h1-h6 elements it produces, and thecomponents.headingoverride only received{level, children}, so there was no supported way to inject one. Result: clicking an outline item changeslocation.hash,document.getElementById(id)returnsnull, and the scroll silently no-ops, exactly as the reporter's repro shows.What changed
inlineText,slugify, anduniqueSlugnow live inpackages/core/src/Markdown/parser.ts(exported, internal to the package).Outline/parseOutlineFromMarkdown.tsdeletes its private copies and imports the shared helpers. Rendered ids and outline ids can no longer drift because they are computed by the same functions.idon h1-h6. AheadingIdMapmemo walks the parsed top-level blocks with one shared duplicate-numbering sequence, mirroringparseOutlineFromMarkdown's traversal exactly (top-level blocks only; headings inside blockquotes and list items are skipped, because the outline never lists them and letting them consume slugs would shift the duplicate numbering and point outline links at the wrong heading).components.headingoverride receivesid?: string. Backward-compatible type extension; existing overrides that ignore it keep compiling and rendering unchanged. Custom heading components can now attach the id themselves.Markdown.doc.mjsgains a usage note (en/dense) about pairing with Outline;Outline.doc.mjs's "Generate items from markdown" example notes that Markdown renders matching ids.Hook-placement pitfall
The
headingIdMapmemo sits with the other hooks, directly after theblocksmemo and well above thedisplay === 'inline'early return, with a NOTE comment explaining why it must stay there. A revision of the prior attempt was tripped up by a Rules of Hooks violation here; this placement is covered by the existing inline-display tests plus the new suite.The invariant, as a test
Markdown.test.tsxgains aheading idssuite (5 tests):overview,installation, the issue's exact repro shape)setup,setup-1,setup-2)sectionfallback, a code-fence decoy, inline code), every id fromparseOutlineFromMarkdownresolves viaquerySelectorto a rendered h1-h6 whose text matches the item labelcomponents.headingreceives the generated ids, including the deduped oneFull run:
packages/core/src/Markdown+packages/core/src/Outline= 7 files, 313 tests, all passing, includingparser.perf.test.ts(slug helpers are appended utilities; the parse hot path is untouched).Prior attempt
#4191 (closed unmerged) had the right blueprint and this PR credits its direction. Differences here: the slug helpers are truly deduplicated (Outline imports the parser's functions instead of keeping a second copy), the parity invariant is enforced by a test that runs both code paths against the same source, nested-heading behavior is explicit and tested rather than incidental, and the
components.headingidprop is documented in the type plus the doc files.Reviewer flags
parseOutlineFromMarkdownexactly was prioritized over decorating every heading. If ids on nested headings are wanted, both traversals should be extended together in a follow-up so numbering stays in sync.parser.tsbut not re-exported fromMarkdown/index.ts, keeping the public API surface unchanged. Happy to expose them publicly if maintainers prefer.idis applied to the default heading element as a plain JSX attribute ahead of themergeProps(themeProps(...), stylex.props(...))spread; neither source emits anid, so there is no collision today.