astro
astro copied to clipboard
Named slots do not work in MDX sometimes
What version of astro are you using?
1.1.5
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
npm
What operating system are you using?
Windows
Describe the Bug
When the text for the default slot is not wrapped in a HTML tag (e.g. <p>) then the named slots' content is rendered in the default slots' location.
MyComponent.astro
<h1>My Component</h1>
Before slot: <slot name="before" /><br/>
Text inbetween before and default.<br/>
Default slot: <slot /><br/>
Text inbetween default and after.<br/>
After slot: <slot name="after" /><br/>
The end
Test.mdx
import MyComponent from "../../components/MyComponent.astro"
<MyComponent>
<p slot="before" style="color: blue;">Before slot text.</p>
Default slot text.
<p slot="after" style="color: red;">After slot text.</p>
</MyComponent>
leads to

But when I do it like this it's working as expected.
<MyComponent>
<p slot="before" style="color: blue;">Before slot text.</p>
<p>Default slot text.</p>
<p slot="after" style="color: red;">After slot text.</p>
</MyComponent>

Not sure if I'm missing something, but I would've expected both examples to work the same. It's reproducible on my local machine, but I wasn't able to reproduce it on StackBlitz. There, both work.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-21chqj?file=src/pages/example.mdx
Participation
- [ ] I am willing to submit a pull request for this issue.