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:
parent
5fb7c9383a
commit
90b715d5c8
3 changed files with 45 additions and 1 deletions
5
.changeset/large-cougars-cough.md
Normal file
5
.changeset/large-cougars-cough.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix Astro-in-MDX dashes in slot attr
|
|
@ -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];
|
||||
|
|
|
@ -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>');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue