Fix inlined hoisted scripts and SSR (#3593)
* Fix inlined hoisted scripts and SSR * Adds a changeset
This commit is contained in:
parent
56a99bebbe
commit
0e2314d8e5
4 changed files with 49 additions and 1 deletions
5
.changeset/loud-bikes-pay.md
Normal file
5
.changeset/loud-bikes-pay.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes uses of inline hoisted scripts in SSR
|
|
@ -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);
|
||||
|
||||
|
|
9
packages/astro/test/fixtures/ssr-hoisted-script/src/pages/index.astro
vendored
Normal file
9
packages/astro/test/fixtures/ssr-hoisted-script/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Testing</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Testing</h1>
|
||||
<script>console.log('hello world');</script>
|
||||
</body>
|
||||
</html>
|
34
packages/astro/test/ssr-hoisted-script.test.js
Normal file
34
packages/astro/test/ssr-hoisted-script.test.js
Normal file
|
@ -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);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue