-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Support rendering <Fragment>
in MDX <Content />
component
#5522
Conversation
🦋 Changeset detectedLatest commit: eb6baf7 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Includes testing use of `<Fragment slot="...">`
No longer needed as this is fixed for all MDX content now within the MDX integration
// Fragment import should already be injected, but check just to be safe. | ||
const importsFromJSXRuntime = moduleImports | ||
.filter(({ n }) => n === 'astro/jsx-runtime') | ||
.map(({ ss, se }) => code.substring(ss, se)); | ||
const hasFragmentImport = importsFromJSXRuntime.some((statement) => | ||
/[\s,{](Fragment,|Fragment\s*})/.test(statement) | ||
); | ||
if (!hasFragmentImport) { | ||
code = 'import { Fragment } from "astro/jsx-runtime"\n' + code; | ||
} |
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.
Turns out the parsed imports aren’t in the friendliest of formats. This is pretty thorough and will inject the import if it doesn’t find one. If you think an error in that scenario would be more appropriate, let me know.
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.
It was Frag
meant to be that you'd find this 🙏
Changes
<Content />
fails for MDX file containing<Fragment>
#5519MDXContent
render function so we can pass in our definition ofFragment
— otherwiseFragment
is unsupported when rendering MDX using<Content />
Testing
Expanded the
mdx-component
fixture/test suite to include an exampleWithFragment.mdx
file which we test renders as expected.Docs
Bug fix only, should match existing docs expectations.