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 Astro.slots.render for mdx #4973

Merged
merged 2 commits into from
Oct 4, 2022
Merged

Support Astro.slots.render for mdx #4973

merged 2 commits into from
Oct 4, 2022

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Oct 4, 2022

Changes

Fix #4826

The Astro.slots.render API only renders Astro slots, but not JSX slots. This PR updates the API to support rendering JSX slots.

Testing

Copied astro-slots tests for Astro.slots.render for mdx.

Docs

N/A. this should be working in the first place.

@changeset-bot
Copy link

changeset-bot bot commented Oct 4, 2022

🦋 Changeset detected

Latest commit: 0392db9

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: astro Related to the core `astro` package (scope) label Oct 4, 2022
Comment on lines +105 to +118
// Astro
const expression = getFunctionExpression(component);
if (expression) {
const slot = expression(...args);
return await renderSlot(this.#result, slot).then((res) =>
res != null ? String(res) : res
);
}
// JSX
if (typeof component === 'function') {
return await renderJSX(this.#result, component(...args)).then((res) =>
res != null ? String(res) : res
);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This mixes JSX rendering into Astro.slots.render. I'm not sure if this is fine architecture-wise.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that this is a bit odd but I can't think of a better way. I think it's ok for now.

Copy link
Contributor

@matthewp matthewp left a comment

Choose a reason for hiding this comment

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

Great tests, thanks!

@matthewp matthewp merged commit c733d4f into main Oct 4, 2022
@matthewp matthewp deleted the jsx-slot-render branch October 4, 2022 14:18
@astrobot-houston astrobot-houston mentioned this pull request Oct 4, 2022
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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Astro.slots.render function does not work when invoked from MDX file
2 participants