fix: do not render headings with no content#944
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@moshams272 is attempting to deploy a commit to the OpenJS Foundation Team on Vercel. A member of the Team first needs to authorize it. |
PR SummaryLow Risk Overview The spec ( The parser comment clarifies that the injected heading is structural only and is not rendered. Reviewed by Cursor Bugbot for commit bee146c. Bugbot is set up for automated code reviews on this repo. Configure here. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #944 +/- ##
==========================================
- Coverage 86.20% 86.18% -0.02%
==========================================
Files 195 195
Lines 17674 17679 +5
Branches 1608 1609 +1
==========================================
+ Hits 15235 15237 +2
- Misses 2433 2436 +3
Partials 6 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a0c54a2. Configure here.
|
Can you:
|
you mean for headings only, right? |
|
yes sorry |
a0c54a2 to
bee146c
Compare
| // If the document has no headings but it has content, we add a fake heading to the top, it will not be rendered | ||
| if (headingNodes.length === 0 && tree.children.length > 0) { | ||
| tree.children.unshift(createTree('heading', { depth: 1 }, [])); | ||
| } |
There was a problem hiding this comment.
Should we just remove this statement... Why are we adding a fake heading in the first place?
Then, createHeadings won't need a fast path
|
this feels very related to notions within #931 |
Sort of, yes. We have one page without a heading, since we add the heading via JSX |

Description
Currently, if an MDX page lacks an ATX H1 (e.g., when the
h1is built into a custom React component),doc-kitautomatically injects an emptyh1to satisfy AST structural requirements and metadata generation.However, this leads to an issue for MDX: if it renders its own custom
h1in a React component, the final HTML ends up with twoh1tags (one fromdoc-kit, one from the component), breaking SEO and Accessibility.The current workaround involves forcing a
# Headingin markdown and visually hiding it via CSS (sr-only), which is a hack.This PR still injects an empty
h1, but it doesn't render the empty headings in general to DOM.Validation
Tested on
webpack-doc-kit:Before:

After:

Related Issues
None
Check List
node --run testand all tests passed.node --run format&node --run lint.