Support rendering <Fragment> in MDX <Content /> component#5522
Merged
Support rendering <Fragment> in MDX <Content /> component#5522
<Fragment> in MDX <Content /> component#5522Conversation
🦋 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 |
delucis
commented
Dec 3, 2022
1 task
Includes testing use of `<Fragment slot="...">`
No longer needed as this is fixed for all MDX content now within the MDX integration
delucis
commented
Dec 3, 2022
delucis
commented
Dec 5, 2022
Comment on lines
+137
to
+146
| // 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; | ||
| } |
Member
Author
There was a problem hiding this comment.
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.
bholmesdev
approved these changes
Dec 5, 2022
Contributor
bholmesdev
left a comment
There was a problem hiding this comment.
It was Fragmeant to be that you'd find this 🙏
Merged
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.
Changes
<Content />fails for MDX file containing<Fragment>#5519MDXContentrender function so we can pass in our definition ofFragment— otherwiseFragmentis unsupported when rendering MDX using<Content />Testing
Expanded the
mdx-componentfixture/test suite to include an exampleWithFragment.mdxfile which we test renders as expected.Docs
Bug fix only, should match existing docs expectations.