summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/loud-bikes-pay.md5
-rw-r--r--packages/astro/src/core/app/index.ts2
-rw-r--r--packages/astro/test/fixtures/ssr-hoisted-script/src/pages/index.astro9
-rw-r--r--packages/astro/test/ssr-hoisted-script.test.js34
4 files changed, 49 insertions, 1 deletions
diff --git a/.changeset/loud-bikes-pay.md b/.changeset/loud-bikes-pay.md
new file mode 100644
index 000000000..937f14dae
--- /dev/null
+++ b/.changeset/loud-bikes-pay.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fixes uses of inline hoisted scripts in SSR
diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts
index dbda3cd44..81cfe106a 100644
--- a/packages/astro/src/core/app/index.ts
+++ b/packages/astro/src/core/app/index.ts
@@ -80,7 +80,7 @@ export class App {
const links = createLinkStylesheetElementSet(info.links, manifest.site);
const filteredScripts = info.scripts.filter(
- (script) => typeof script !== 'string' && script?.stage !== 'head-inline'
+ (script) => typeof script === 'string' || script?.stage !== 'head-inline'
) as string[];
const scripts = createModuleScriptElementWithSrcSet(filteredScripts, manifest.site);
diff --git a/packages/astro/test/fixtures/ssr-hoisted-script/src/pages/index.astro b/packages/astro/test/fixtures/ssr-hoisted-script/src/pages/index.astro
new file mode 100644
index 000000000..6543f0847
--- /dev/null
+++ b/packages/astro/test/fixtures/ssr-hoisted-script/src/pages/index.astro
@@ -0,0 +1,9 @@
+<html>
+ <head>
+ <title>Testing</title>
+ </head>
+ <body>
+ <h1>Testing</h1>
+ <script>console.log('hello world');</script>
+ </body>
+</html>
diff --git a/packages/astro/test/ssr-hoisted-script.test.js b/packages/astro/test/ssr-hoisted-script.test.js
new file mode 100644
index 000000000..134744ae9
--- /dev/null
+++ b/packages/astro/test/ssr-hoisted-script.test.js
@@ -0,0 +1,34 @@
+import { expect } from 'chai';
+import { load as cheerioLoad } from 'cheerio';
+import { loadFixture } from './test-utils.js';
+import testAdapter from './test-adapter.js';
+
+describe('Hoisted scripts in SSR', () => {
+ /** @type {import('./test-utils').Fixture} */
+ let fixture;
+
+ before(async () => {
+ fixture = await loadFixture({
+ root: './fixtures/ssr-hoisted-script/',
+ experimental: {
+ ssr: true,
+ },
+ adapter: testAdapter(),
+ });
+ await fixture.build();
+ });
+
+ async function fetchHTML(path) {
+ const app = await fixture.loadTestAdapterApp();
+ const request = new Request('http://example.com' + path);
+ const response = await app.render(request);
+ const html = await response.text();
+ return html;
+ }
+
+ it('Inlined scripts get included', async () => {
+ const html = await fetchHTML('/');
+ const $ = cheerioLoad(html);
+ expect($('script').length).to.equal(1);
+ });
+});