mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
fix(astro/core): Do not add base to hoisted script body (#5720)
* fix(astro/core): Do not add base to hoisted script body * fix(astro/core): Add base path to hoisted .js files only * fix(astro/core): undo style changes
This commit is contained in:
parent
c2844a79c8
commit
fe316be86f
3 changed files with 28 additions and 3 deletions
5
.changeset/good-carpets-confess.md
Normal file
5
.changeset/good-carpets-confess.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Do not add base path to a hoisted script body
|
|
@ -44,9 +44,7 @@ const _manifest = Object.assign(_deserializeManifest('${manifestReplace}'), {
|
|||
renderers: _main.renderers
|
||||
});
|
||||
const _args = ${adapter.args ? JSON.stringify(adapter.args) : 'undefined'};
|
||||
|
||||
export * from '${pagesVirtualModuleId}';
|
||||
|
||||
${
|
||||
adapter.exports
|
||||
? `const _exports = adapter.createExports(_manifest, _args);
|
||||
|
@ -165,9 +163,11 @@ function buildManifest(
|
|||
for (const pageData of eachServerPageData(internals)) {
|
||||
const scripts: SerializedRouteInfo['scripts'] = [];
|
||||
if (pageData.hoistedScript) {
|
||||
const hoistedValue = pageData.hoistedScript.value
|
||||
const value = hoistedValue.endsWith('.js') ? joinBase(hoistedValue) : hoistedValue
|
||||
scripts.unshift(
|
||||
Object.assign({}, pageData.hoistedScript, {
|
||||
value: joinBase(pageData.hoistedScript.value),
|
||||
value,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
@ -29,4 +29,24 @@ describe('Hoisted scripts in SSR', () => {
|
|||
const $ = cheerioLoad(html);
|
||||
expect($('script').length).to.equal(1);
|
||||
});
|
||||
|
||||
describe('base path', () => {
|
||||
const base = '/hello';
|
||||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({
|
||||
root: './fixtures/ssr-hoisted-script/',
|
||||
output: 'server',
|
||||
adapter: testAdapter(),
|
||||
base,
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
it('Inlined scripts get included without base path in the script', async () => {
|
||||
const html = await fetchHTML('/hello/');
|
||||
const $ = cheerioLoad(html);
|
||||
expect($('script').html()).to.equal('console.log("hello world");\n');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue