0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00

Fixes JSX usage of slots with dashes in their name (#5080)

* Fixes JSX usage of slots with dashes in their name

* Adding a changeset
This commit is contained in:
Matthew Phillips 2022-10-13 17:40:17 -04:00 committed by GitHub
parent 5fb7c9383a
commit 90b715d5c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix Astro-in-MDX dashes in slot attr

View file

@ -10,7 +10,7 @@ export interface AstroVNode {
props: Record<string, any>;
}
const toSlotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());
const toSlotName = (slotAttr: string) => slotAttr;
export function isVNode(vnode: any): vnode is AstroVNode {
return vnode && typeof vnode === 'object' && vnode[AstroJSX];

View file

@ -49,5 +49,44 @@ describe('core/render', () => {
const html = await response.text();
expect(html).to.include('<div><p class="n">works</p></div>');
});
it('Can render slots with a dash in the name', async () => {
const Wrapper = createComponent((result, _props, slots = {}) => {
return render`<div>${renderSlot(result, slots['my-slot'])}</div>`;
});
const Page = createAstroJSXComponent(() => {
return jsx('main', {
children: [
jsx(Wrapper, {
// Children as an array
children: [
jsx('p', {
slot: 'my-slot',
className: 'n',
children: 'works'
})
]
}),
jsx(Wrapper, {
// Children as a VNode
children: jsx('p', {
slot: 'my-slot',
className: 'p',
children: 'works'
})
})
]
})
});
const ctx = createRenderContext({ request: new Request('http://example.com/' )});
const response = await renderPage(createAstroModule(Page), ctx, env);
expect(response.status).to.equal(200);
const html = await response.text();
expect(html).to.include('<main><div><p class="n">works</p></div><div><p class="p">works</p></div></main>');
});
});
});