summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/good-carpets-confess.md5
-rw-r--r--packages/astro/src/core/build/vite-plugin-ssr.ts6
-rw-r--r--packages/astro/test/ssr-hoisted-script.test.js20
3 files changed, 28 insertions, 3 deletions
diff --git a/.changeset/good-carpets-confess.md b/.changeset/good-carpets-confess.md
new file mode 100644
index 000000000..c7095d3aa
--- /dev/null
+++ b/.changeset/good-carpets-confess.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Do not add base path to a hoisted script body
diff --git a/packages/astro/src/core/build/vite-plugin-ssr.ts b/packages/astro/src/core/build/vite-plugin-ssr.ts
index 928e3820e..f35a5270a 100644
--- a/packages/astro/src/core/build/vite-plugin-ssr.ts
+++ b/packages/astro/src/core/build/vite-plugin-ssr.ts
@@ -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,
})
);
}
diff --git a/packages/astro/test/ssr-hoisted-script.test.js b/packages/astro/test/ssr-hoisted-script.test.js
index 7d31875ff..49e1e7b2f 100644
--- a/packages/astro/test/ssr-hoisted-script.test.js
+++ b/packages/astro/test/ssr-hoisted-script.test.js
@@ -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');
+ });
+ });
});