-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix head injection misplacement with Astro.slots.render() (#6196)
* Fix head injection misplacement with Astro.slots.render() * Adding a changeset * Fix case of JSX with no layout * missing break
- Loading branch information
Showing
19 changed files
with
216 additions
and
32 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 head injection misplacement with Astro.slots.render() |
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
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
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
2 changes: 1 addition & 1 deletion
2
...t/fixtures/head-injection-md/package.json → ...test/fixtures/head-injection/package.json
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
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/head-injection/src/components/RegularSlot.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,8 @@ | ||
<style> | ||
div { | ||
font-weight: bolder; | ||
} | ||
</style> | ||
<div> | ||
<slot /> | ||
</div> |
12 changes: 12 additions & 0 deletions
12
packages/astro/test/fixtures/head-injection/src/components/SlotRenderComponent.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,12 @@ | ||
--- | ||
const html = await Astro.slots.render('slot-name'); | ||
--- | ||
<div class="p-sample"> | ||
<Fragment set:html={html} /> | ||
</div> | ||
|
||
<style> | ||
.p-sample { | ||
color: red; | ||
} | ||
</style> |
7 changes: 7 additions & 0 deletions
7
packages/astro/test/fixtures/head-injection/src/components/SlotRenderLayout.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 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> </head> | ||
<body> | ||
<slot /> | ||
</body> | ||
</html> |
25 changes: 25 additions & 0 deletions
25
packages/astro/test/fixtures/head-injection/src/components/SlotsRender.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,25 @@ | ||
--- | ||
export interface Props { | ||
title: string; | ||
subtitle: string; | ||
content?: string; | ||
} | ||
const { | ||
title, | ||
subtitle = await Astro.slots.render("subtitle"), | ||
content = await Astro.slots.render("content"), | ||
} = Astro.props; | ||
--- | ||
|
||
<style> | ||
section { | ||
background: slategrey; | ||
} | ||
</style> | ||
<section> | ||
<div> | ||
{title && <h1>{title}</h1>} | ||
{subtitle && <p set:html={subtitle} />} | ||
{content && <div set:html={content} />} | ||
</div> | ||
</section> |
File renamed without changes.
24 changes: 24 additions & 0 deletions
24
packages/astro/test/fixtures/head-injection/src/pages/with-slot-in-render-slot.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,24 @@ | ||
--- | ||
import Layout from '../components/Layout.astro'; | ||
import SlotsRender from '../components/SlotsRender.astro'; | ||
--- | ||
|
||
<Layout> | ||
<SlotsRender | ||
title="Lorem ipsum lorem" | ||
subtitle="At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti" | ||
> | ||
<Fragment slot="content"> | ||
<p> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore | ||
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo | ||
consequat. | ||
</p> | ||
|
||
<p class="mt-4"> | ||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur | ||
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | ||
</p> | ||
</Fragment> | ||
</SlotsRender> | ||
</Layout> |
11 changes: 11 additions & 0 deletions
11
packages/astro/test/fixtures/head-injection/src/pages/with-slot-in-slot.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,11 @@ | ||
--- | ||
import Layout from "../components/SlotRenderLayout.astro"; | ||
import RegularSlot from "../components/RegularSlot.astro" | ||
--- | ||
<Layout> | ||
<RegularSlot> | ||
<RegularSlot> | ||
<p slot="slot-name">Paragraph.</p> | ||
</RegularSlot> | ||
</RegularSlot> | ||
</Layout> |
9 changes: 9 additions & 0 deletions
9
packages/astro/test/fixtures/head-injection/src/pages/with-slot-render.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,9 @@ | ||
--- | ||
import Layout from "../components/SlotRenderLayout.astro"; | ||
import Component from "../components/SlotRenderComponent.astro" | ||
--- | ||
<Layout> | ||
<Component> | ||
<p slot="slot-name">Paragraph.</p> | ||
</Component> | ||
</Layout> |
This file was deleted.
Oops, something went wrong.
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,55 @@ | ||
import { expect } from 'chai'; | ||
import * as cheerio from 'cheerio'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Head injection', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/head-injection/', | ||
}); | ||
}); | ||
|
||
describe('build', () => { | ||
before(async () => { | ||
await fixture.build(); | ||
}); | ||
|
||
describe('Markdown', () => { | ||
it('only injects head content once', async () => { | ||
const html = await fixture.readFile(`/index.html`); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('head link[rel=stylesheet]')).to.have.a.lengthOf(1); | ||
}); | ||
}); | ||
|
||
describe('Astro components', () => { | ||
it('Using slots within slots', async () => { | ||
const html = await fixture.readFile('/with-slot-in-slot/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('head link[rel=stylesheet]')).to.have.a.lengthOf(1); | ||
expect($('body link[rel=stylesheet]')).to.have.a.lengthOf(0); | ||
}); | ||
|
||
it('Using slots with Astro.slots.render()', async () => { | ||
const html = await fixture.readFile('/with-slot-render/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('head link[rel=stylesheet]')).to.have.a.lengthOf(1); | ||
expect($('body link[rel=stylesheet]')).to.have.a.lengthOf(0); | ||
}); | ||
|
||
it('Using slots within slots using Astro.slots.render()', async () => { | ||
const html = await fixture.readFile('/with-slot-in-render-slot/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('head link[rel=stylesheet]')).to.have.a.lengthOf(2); | ||
expect($('body link[rel=stylesheet]')).to.have.a.lengthOf(0); | ||
}); | ||
}); | ||
}); | ||
}); |
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
22 changes: 22 additions & 0 deletions
22
...integrations/mdx/test/fixtures/css-head-mdx/src/pages/noLayoutWithComponent.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,22 @@ | ||
--- | ||
title: 'Lorem' | ||
description: 'Lorem ipsum dolor sit amet' | ||
pubDate: 'Jul 02 2022' | ||
--- | ||
|
||
import MyComponent from '../components/HelloWorld.astro'; | ||
|
||
|
||
## Lorem | ||
|
||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | ||
|
||
## Lorem 2 | ||
|
||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | ||
|
||
<MyComponent /> | ||
|
||
## Lorem 3 | ||
|
||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.