diff options
author | 2023-02-07 10:56:32 -0500 | |
---|---|---|
committer | 2023-02-07 10:56:32 -0500 | |
commit | d1f5611febfd020cca4078c71bafe599015edd16 (patch) | |
tree | f8fc9ce932f2dcaa559602ef66b77afa795b764f /packages/integrations/mdx/test | |
parent | cee70f5c6ac9b0d2edc1f8a6f8f5043605576026 (diff) | |
download | astro-d1f5611febfd020cca4078c71bafe599015edd16.tar.gz astro-d1f5611febfd020cca4078c71bafe599015edd16.tar.zst astro-d1f5611febfd020cca4078c71bafe599015edd16.zip |
Add additional scoping for head buffering (#6152)
* Add additional scoping for head buffering
* Add test for direct usage of nested component
* Add special scoping for Astro.scopes.render()
* Generate propagation map during the build
* Move to a maybeHead instruction
* Properly serialize for SSR
* More conservative scoping
* Maybe had should honor result._metadata.hasRenderedHead
* Properly type slots
* Allow template result to be passed
* Add changeset
Diffstat (limited to 'packages/integrations/mdx/test')
14 files changed, 150 insertions, 0 deletions
diff --git a/packages/integrations/mdx/test/css-head-mdx.test.js b/packages/integrations/mdx/test/css-head-mdx.test.js index 2b1dcdfe7..c38f23701 100644 --- a/packages/integrations/mdx/test/css-head-mdx.test.js +++ b/packages/integrations/mdx/test/css-head-mdx.test.js @@ -29,5 +29,32 @@ describe('Head injection w/ MDX', () => { const scripts = document.querySelectorAll('head script[type=module]'); expect(scripts).to.have.a.lengthOf(1); }); + + it('injects into the head for content collections', async () => { + const html = await fixture.readFile('/posts/test/index.html'); + const { document } = parseHTML(html); + + const links = document.querySelectorAll('head link[rel=stylesheet]'); + expect(links).to.have.a.lengthOf(1); + }); + + it('injects content from a component using Content#render()', async () => { + const html = await fixture.readFile('/DirectContentUsage/index.html'); + const { document } = parseHTML(html); + + const links = document.querySelectorAll('head link[rel=stylesheet]'); + expect(links).to.have.a.lengthOf(1); + + const scripts = document.querySelectorAll('head script[type=module]'); + expect(scripts).to.have.a.lengthOf(2); + }); + + it('Using component using slots.render() API', async () => { + const html = await fixture.readFile('/remote/index.html'); + const { document } = parseHTML(html); + + const links = document.querySelectorAll('head link[rel=stylesheet]'); + expect(links).to.have.a.lengthOf(1); + }); }); }); diff --git a/packages/integrations/mdx/test/fixtures/css-head-mdx/package.json b/packages/integrations/mdx/test/fixtures/css-head-mdx/package.json new file mode 100644 index 000000000..3c3c1e5a5 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/css-head-mdx/package.json @@ -0,0 +1,10 @@ +{ + "name": "@test/mdx-css-head-mdx", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*", + "@astrojs/mdx": "workspace:*", + "astro-remote": "0.2.3" + } +} diff --git a/packages/integrations/mdx/test/fixtures/css-head-mdx/src/components/P.astro b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/components/P.astro new file mode 100644 index 000000000..071e08a12 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/components/P.astro @@ -0,0 +1,3 @@ +<p> + <slot /> +</p> diff --git a/packages/integrations/mdx/test/fixtures/css-head-mdx/src/components/SmallCaps.astro b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/components/SmallCaps.astro new file mode 100644 index 000000000..a0bd6e1f1 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/components/SmallCaps.astro @@ -0,0 +1,3 @@ +--- +--- +<span style={{fontVariant: "small-caps"}}><slot /></span> diff --git a/packages/integrations/mdx/test/fixtures/css-head-mdx/src/components/UsingMdx.astro b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/components/UsingMdx.astro new file mode 100644 index 000000000..1804388b0 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/components/UsingMdx.astro @@ -0,0 +1,8 @@ +--- +import { getEntryBySlug } from 'astro:content'; + +const launchWeek = await getEntryBySlug('blog', 'using-mdx'); +const { Content } = await launchWeek.render(); +--- + +<Content /> diff --git a/packages/integrations/mdx/test/fixtures/css-head-mdx/src/components/WithHoistedScripts.astro b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/components/WithHoistedScripts.astro new file mode 100644 index 000000000..0b8c4445f --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/components/WithHoistedScripts.astro @@ -0,0 +1,6 @@ +--- +--- + +<script> + console.log('hoisted') + </script> diff --git a/packages/integrations/mdx/test/fixtures/css-head-mdx/src/content/blog/_styles.css b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/content/blog/_styles.css new file mode 100644 index 000000000..1379b29c0 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/content/blog/_styles.css @@ -0,0 +1,3 @@ +body { + color: red !important; +} diff --git a/packages/integrations/mdx/test/fixtures/css-head-mdx/src/content/blog/using-mdx.mdx b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/content/blog/using-mdx.mdx new file mode 100644 index 000000000..917fc3331 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/content/blog/using-mdx.mdx @@ -0,0 +1,6 @@ +import './_styles.css'; +import WithHoistedScripts from '../../components/WithHoistedScripts.astro'; + +# Using mdx + +<WithHoistedScripts /> diff --git a/packages/integrations/mdx/test/fixtures/css-head-mdx/src/content/posts/test.mdx b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/content/posts/test.mdx new file mode 100644 index 000000000..0bb1153ca --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/content/posts/test.mdx @@ -0,0 +1,5 @@ +--- +title: Testing +--- + +<SmallCaps>A test file</SmallCaps> diff --git a/packages/integrations/mdx/test/fixtures/css-head-mdx/src/layouts/ContentLayout.astro b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/layouts/ContentLayout.astro new file mode 100644 index 000000000..7b234e868 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/layouts/ContentLayout.astro @@ -0,0 +1,24 @@ +--- +export interface Props { + title: string; +} + +const { title } = Astro.props; +--- + +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="UTF-8" /> + <meta name="viewport" content="width=device-width" /> + <link rel="icon" type="image/svg+xml" href="/favicon.svg" /> + <meta name="generator" content={Astro.generator} /> + <title>{title}</title> + <style is:global> + @import "../styles/global.css"; + </style> + </head> + <body> + <slot /> + </body> +</html> diff --git a/packages/integrations/mdx/test/fixtures/css-head-mdx/src/pages/DirectContentUsage.astro b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/pages/DirectContentUsage.astro new file mode 100644 index 000000000..cbf4295a7 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/pages/DirectContentUsage.astro @@ -0,0 +1,17 @@ +--- +import UsingMdx from '../components/UsingMdx.astro' +--- + +<html lang="en"> + <head> + <meta charset="utf-8" /> + <link rel="icon" type="image/svg+xml" href="/favicon.svg" /> + <meta name="viewport" content="width=device-width" /> + <meta name="generator" content={Astro.generator} /> + <title>Astro</title> + </head> + <body> + <h1>Astro</h1> + <UsingMdx /> + </body> +</html> diff --git a/packages/integrations/mdx/test/fixtures/css-head-mdx/src/pages/posts/[post].astro b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/pages/posts/[post].astro new file mode 100644 index 000000000..7d6ca0ca4 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/pages/posts/[post].astro @@ -0,0 +1,18 @@ +--- +import { getCollection } from 'astro:content'; +import Layout from '../../layouts/ContentLayout.astro'; +import SmallCaps from '../../components/SmallCaps.astro'; + +export async function getStaticPaths() { + const entries = await getCollection('posts'); + return entries.map(entry => { + return {params: { post: entry.slug }, props: { entry }, + }}); +} + +const { entry } = Astro.props; +const { Content } = await entry.render(); +--- +<Layout title=""> + <Content components={{ SmallCaps }} /> +</Layout> diff --git a/packages/integrations/mdx/test/fixtures/css-head-mdx/src/pages/remote.astro b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/pages/remote.astro new file mode 100644 index 000000000..9a7b76a10 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/pages/remote.astro @@ -0,0 +1,17 @@ +--- +import '../styles/global.css' +import Layout from '../layouts/One.astro'; +import Paragraph from '../components/P.astro'; +import { Markdown } from 'astro-remote' +--- + +<Layout title="Welcome to Astro."> + <main> + <Markdown + components={{ + p: Paragraph, + }}> + **Removing p component fixes the problem** + </Markdown> + </main> +</Layout> diff --git a/packages/integrations/mdx/test/fixtures/css-head-mdx/src/styles/global.css b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/styles/global.css new file mode 100644 index 000000000..e1450526f --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/css-head-mdx/src/styles/global.css @@ -0,0 +1,3 @@ +html { + font-weight: bolder; +} |