summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/fluffy-wolves-sneeze.md5
-rw-r--r--packages/astro/src/runtime/server/index.ts2
-rw-r--r--packages/astro/test/astro-partial-html.test.js21
-rw-r--r--packages/astro/test/fixtures/astro-partial-html/src/components/Head.astro3
-rw-r--r--packages/astro/test/fixtures/astro-partial-html/src/pages/head.astro15
5 files changed, 45 insertions, 1 deletions
diff --git a/.changeset/fluffy-wolves-sneeze.md b/.changeset/fluffy-wolves-sneeze.md
new file mode 100644
index 000000000..87efc45de
--- /dev/null
+++ b/.changeset/fluffy-wolves-sneeze.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fix hydration when rendering `<head>` elements inside of a component
diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts
index 0d468a9d3..6cf520563 100644
--- a/packages/astro/src/runtime/server/index.ts
+++ b/packages/astro/src/runtime/server/index.ts
@@ -544,7 +544,7 @@ export async function renderToString(
}
let template = await renderAstroComponent(Component);
- return replaceHeadInjection(result, template);
+ return template;
}
export async function renderPage(
diff --git a/packages/astro/test/astro-partial-html.test.js b/packages/astro/test/astro-partial-html.test.js
index 15fc5ee36..f47857dea 100644
--- a/packages/astro/test/astro-partial-html.test.js
+++ b/packages/astro/test/astro-partial-html.test.js
@@ -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));
+ });
+});
diff --git a/packages/astro/test/fixtures/astro-partial-html/src/components/Head.astro b/packages/astro/test/fixtures/astro-partial-html/src/components/Head.astro
new file mode 100644
index 000000000..a77dd1dd8
--- /dev/null
+++ b/packages/astro/test/fixtures/astro-partial-html/src/components/Head.astro
@@ -0,0 +1,3 @@
+<head>
+ <title>Hello world!</title>
+</head>
diff --git a/packages/astro/test/fixtures/astro-partial-html/src/pages/head.astro b/packages/astro/test/fixtures/astro-partial-html/src/pages/head.astro
new file mode 100644
index 000000000..635b09699
--- /dev/null
+++ b/packages/astro/test/fixtures/astro-partial-html/src/pages/head.astro
@@ -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>
+