Skip to content

Commit

Permalink
Fix slot tags uncleaned in HTML String (#6948)
Browse files Browse the repository at this point in the history
* fix: slot regex

* add slot test

* change set

* add test
  • Loading branch information
cyanxiao committed May 1, 2023
1 parent dc062f6 commit 50975f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/sharp-jobs-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Placeholders for slots are cleaned in HTML String that is rendered
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/render/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
if (isPage || renderer?.name === 'astro:jsx') {
yield html;
} else if (html && html.length > 0) {
yield markHTMLString(html.replace(/\<\/?astro-slot\>/g, ''));
yield markHTMLString(html.replace(/\<\/?astro-slot\b[^>]*>/g, ''));
} else {
yield '';
}
Expand Down
6 changes: 6 additions & 0 deletions packages/astro/test/astro-slot-with-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ describe('Slots with client: directives', () => {
const $ = cheerio.load(html);
expect($('script')).to.have.a.lengthOf(1);
});

it('Astro slot tags are cleaned', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('astro-slot')).to.have.a.lengthOf(0);
});
});

0 comments on commit 50975f2

Please sign in to comment.