-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(mdx-loader): the table-of-contents should display props passed to headings of imported MDX partials #9773
base: main
Are you sure you want to change the base?
Conversation
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
I've come up with a crude way of preserving the data passed to props of Markdown partials. For now, this method only works if the prop is a literal, since the prop values are collected at build time. While not perfect, having only literals is almost always all that is needed when working with partials. Nonetheless, I think some work can be moved to runtime, to allow the use of any arbitrary expressions. |
⚡️ Lighthouse report for the deploy preview of this PR
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅 to be honest I'm not super fan of this
This only works in some cases and does not feel super robust either, and we'll have to handle the users complaining about things it does not support.
I'd prefer to explore another solution: what if we didn't stringify the headings in the first place?
What if we converted headings to JSX instead?
The TOC structure could look like:
export const toc = [
{
"value": <>Doc Heading</>,
"id": "doc-heading",
"level": 2
},
...__tocPartial(props),
]
Pre-flight checklist
Motivation
This PR allows the usage of props in partial MDX files.
Test Plan
This PR will be tested via dogfooding.
Test links
Deploy preview: https://deploy-preview-9773--docusaurus-2.netlify.app/
Relevant dogfooding page: https://deploy-preview-9773--docusaurus-2.netlify.app/tests/docs/tests/toc-partials/props
Related issues/PRs
fix #9772