From 50975f2ea3a59f9e023cc631a9372c0c7986eec9 Mon Sep 17 00:00:00 2001 From: Chell Date: Mon, 1 May 2023 16:49:23 +0200 Subject: [PATCH] Fix slot tags uncleaned in HTML String (#6948) * fix: slot regex * add slot test * change set * add test --- .changeset/sharp-jobs-grow.md | 5 +++++ packages/astro/src/runtime/server/render/component.ts | 2 +- packages/astro/test/astro-slot-with-client.test.js | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/sharp-jobs-grow.md diff --git a/.changeset/sharp-jobs-grow.md b/.changeset/sharp-jobs-grow.md new file mode 100644 index 0000000000..ab0cf961d3 --- /dev/null +++ b/.changeset/sharp-jobs-grow.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Placeholders for slots are cleaned in HTML String that is rendered diff --git a/packages/astro/src/runtime/server/render/component.ts b/packages/astro/src/runtime/server/render/component.ts index 1c427bf2a4..cc88515226 100644 --- a/packages/astro/src/runtime/server/render/component.ts +++ b/packages/astro/src/runtime/server/render/component.ts @@ -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 ''; } diff --git a/packages/astro/test/astro-slot-with-client.test.js b/packages/astro/test/astro-slot-with-client.test.js index 12e630548c..4ad26dee41 100644 --- a/packages/astro/test/astro-slot-with-client.test.js +++ b/packages/astro/test/astro-slot-with-client.test.js @@ -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); + }); });