Defer head injection until renderPage
(#3408)
* fix(#3195, #3197): only perform head injection for renderPage * chore: add changeset
This commit is contained in:
parent
4dfd341928
commit
b26d48d275
5 changed files with 45 additions and 1 deletions
5
.changeset/fluffy-wolves-sneeze.md
Normal file
5
.changeset/fluffy-wolves-sneeze.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix hydration when rendering `<head>` elements inside of a component
|
|
@ -544,7 +544,7 @@ export async function renderToString(
|
|||
}
|
||||
|
||||
let template = await renderAstroComponent(Component);
|
||||
return replaceHeadInjection(result, template);
|
||||
return template;
|
||||
}
|
||||
|
||||
export async function renderPage(
|
||||
|
|
|
@ -48,3 +48,24 @@ describe('Partial HTML', async () => {
|
|||
expect(href).to.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
describe('Head Component', async () => {
|
||||
let fixture;
|
||||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({
|
||||
root: './fixtures/astro-partial-html/',
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
it('injects Astro hydration scripts', async () => {
|
||||
const html = await fixture.readFile('/head/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
const hydrationId = $('astro-root').attr('uid');
|
||||
|
||||
const script = $('script').html();
|
||||
expect(script).to.match(new RegExp(hydrationId));
|
||||
});
|
||||
});
|
||||
|
|
3
packages/astro/test/fixtures/astro-partial-html/src/components/Head.astro
vendored
Normal file
3
packages/astro/test/fixtures/astro-partial-html/src/components/Head.astro
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
<head>
|
||||
<title>Hello world!</title>
|
||||
</head>
|
15
packages/astro/test/fixtures/astro-partial-html/src/pages/head.astro
vendored
Normal file
15
packages/astro/test/fixtures/astro-partial-html/src/pages/head.astro
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
import Head from '../components/Head.astro';
|
||||
import Component from '../components/Component.jsx';
|
||||
---
|
||||
|
||||
<html>
|
||||
<!-- <head> element delegated to component -->
|
||||
<Head />
|
||||
<body>
|
||||
<Component client:load>
|
||||
<h1>JSX Partial HTML</h1>
|
||||
</Component>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in a new issue