Skip to content
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

Merged
merged 11 commits into from
Dec 5, 2022
Merged

Conversation

delucis
Copy link
Member

@delucis delucis commented Dec 3, 2022

Changes

Testing

Expanded the mdx-component fixture/test suite to include an example WithFragment.mdx file which we test renders as expected.

Docs

Bug fix only, should match existing docs expectations.

@changeset-bot
Copy link

changeset-bot bot commented Dec 3, 2022

🦋 Changeset detected

Latest 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

@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Dec 3, 2022
Includes testing use of `<Fragment slot="...">`
No longer needed as this is fixed for all MDX content now within the MDX integration
@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Dec 3, 2022
@github-actions github-actions bot removed the pkg: astro Related to the core `astro` package (scope) label Dec 3, 2022
@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Dec 3, 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;
}
Copy link
Member Author

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.

Copy link
Contributor

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was Fragmeant to be that you'd find this 🙏

@delucis delucis merged commit efc4363 into main Dec 5, 2022
@delucis delucis deleted the issue/5519 branch December 5, 2022 20:56
@astrobot-houston astrobot-houston mentioned this pull request Dec 5, 2022
@bluwy bluwy mentioned this pull request Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rendering <Content /> fails for MDX file containing <Fragment>
3 participants