Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle edge case in jsx-runtime (#4158)
* fix(#4135): handle edge case in jsx-runtime * test: add mdx test case * chore: fix utils reference * test: fix mdx escape test Co-authored-by: Nate Moore <nate@astro.build>
- Loading branch information
1 parent
e7bee22
commit e569f0a
Showing
8 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Fix edge case where MDX components would be escaped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/integrations/mdx/test/fixtures/mdx-escape/src/components/Em.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<em><slot/></em> | ||
|
||
<style> | ||
em { | ||
color: red; | ||
} | ||
</style> |
1 change: 1 addition & 0 deletions
1
packages/integrations/mdx/test/fixtures/mdx-escape/src/components/P.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p><slot /></p> |
1 change: 1 addition & 0 deletions
1
packages/integrations/mdx/test/fixtures/mdx-escape/src/components/Title.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1><slot/></h1> |
5 changes: 5 additions & 0 deletions
5
packages/integrations/mdx/test/fixtures/mdx-escape/src/pages/html-tag.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import P from '../components/P.astro'; | ||
import Em from '../components/Em.astro'; | ||
|
||
<P>Render <Em>Me</Em></P> | ||
<P><Em>Me</Em></P> |
13 changes: 13 additions & 0 deletions
13
packages/integrations/mdx/test/fixtures/mdx-escape/src/pages/index.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import P from '../components/P.astro'; | ||
import Em from '../components/Em.astro'; | ||
import Title from '../components/Title.astro'; | ||
|
||
export const components = { p: P, em: Em, h1: Title }; | ||
|
||
# Hello _there_ | ||
|
||
# _there_ | ||
|
||
Hello _there_ | ||
|
||
_there_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import mdx from '@astrojs/mdx'; | ||
|
||
import { expect } from 'chai'; | ||
import { parseHTML } from 'linkedom'; | ||
import { loadFixture } from '../../../astro/test/test-utils.js'; | ||
|
||
const FIXTURE_ROOT = new URL('./fixtures/mdx-escape/', import.meta.url); | ||
|
||
describe('MDX frontmatter', () => { | ||
let fixture; | ||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: FIXTURE_ROOT, | ||
integrations: [mdx()], | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
it('does not have unescaped HTML at top-level', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
const { document } = parseHTML(html); | ||
|
||
expect(document.body.textContent).to.not.include('<em'); | ||
}); | ||
|
||
it('does not have unescaped HTML inside html tags', async () => { | ||
const html = await fixture.readFile('/html-tag/index.html'); | ||
const { document } = parseHTML(html); | ||
|
||
expect(document.body.textContent).to.not.include('<em'); | ||
}); | ||
}); |