diff --git a/packages/astro/components/Markdown.astro b/packages/astro/components/Markdown.astro index 862b3a2d4..350b9c317 100644 --- a/packages/astro/components/Markdown.astro +++ b/packages/astro/components/Markdown.astro @@ -20,7 +20,7 @@ const { privateRenderMarkdownDoNotUse: renderMarkdown } = (Astro as any); if (!content) { const { privateRenderSlotDoNotUse: renderSlot } = (Astro as any); content = await renderSlot('default'); - if (content.trim().length > 0) { + if (content !== undefined && content !== null) { content = dedent(content); } } diff --git a/packages/astro/test/astro-markdown.test.js b/packages/astro/test/astro-markdown.test.js index de3a1f996..0d6aae978 100644 --- a/packages/astro/test/astro-markdown.test.js +++ b/packages/astro/test/astro-markdown.test.js @@ -140,4 +140,10 @@ describe('Astro Markdown', () => { // test Markdown rendered correctly via content prop expect($('h1').text()).to.equal('Foo'); }); + + it("doesn't occurs TypeError when no elements", async () => { + const html = await fixture.readFile('/no-elements/index.html'); + // render html without error + expect(html).to.be.ok; + }); }); diff --git a/packages/astro/test/fixtures/astro-markdown/src/pages/no-elements.astro b/packages/astro/test/fixtures/astro-markdown/src/pages/no-elements.astro new file mode 100644 index 000000000..d865e9046 --- /dev/null +++ b/packages/astro/test/fixtures/astro-markdown/src/pages/no-elements.astro @@ -0,0 +1,5 @@ +--- +import { Markdown } from 'astro/components'; +--- + + \ No newline at end of file