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 now treats the depth-1 title as OPTIONAL, RECOMMENDED instead of REQUIRED, and depth-1 semantics use SHOULD rather than MUST for “exactly one” heading. Reviewed by Cursor Bugbot for commit 66b522f. 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.51% +0.31%
==========================================
Files 195 195
Lines 17674 17979 +305
Branches 1608 1634 +26
==========================================
+ Hits 15235 15554 +319
+ Misses 2433 2419 -14
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
There was a problem hiding this comment.
Actually, I was thinking of that and searching for what the effect will be. Let me revise what I found.
There was a problem hiding this comment.
-
While traversing AST, in this file,
parseApiDocextracts content by visiting heading nodesvisit(tree, UNIST.isHeading, (headingNode, index) => {...}}. It uses each heading as an anchor and slices the AST content between it and the next heading. If a document has no headings, thevisitnever fires, andparseApiDocreturns an empty array, which drops all the page content. -
in type.d.ts, The MetadataEntry interface strictly requires heading: HeadingNode (it is not optional).
There was a problem hiding this comment.
I see, so headings are required, I guess. In that case, we should make the default heading something like {project} Documentation, and then in webpack use CSS/postprocessing to remove it
There was a problem hiding this comment.
I just think of accessibility, SEO and other projects that will use doc-kit, instead of pushing elements to the DOM that serve zero visual purpose, we can handle it here.
In the end, that's your decision, guys 😅
|
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.