summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/few-days-refuse.md5
-rw-r--r--packages/astro/src/core/build/vite-plugin-ssr.ts7
-rw-r--r--packages/astro/test/fixtures/ssr-request/src/scripts/inject-script.js1
-rw-r--r--packages/astro/test/ssr-request.test.js28
4 files changed, 32 insertions, 9 deletions
diff --git a/.changeset/few-days-refuse.md b/.changeset/few-days-refuse.md
new file mode 100644
index 000000000..55c595a5e
--- /dev/null
+++ b/.changeset/few-days-refuse.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Include base in 'page' stage injected scripts
diff --git a/packages/astro/src/core/build/vite-plugin-ssr.ts b/packages/astro/src/core/build/vite-plugin-ssr.ts
index 03dc20699..f3c333fa1 100644
--- a/packages/astro/src/core/build/vite-plugin-ssr.ts
+++ b/packages/astro/src/core/build/vite-plugin-ssr.ts
@@ -146,7 +146,12 @@ function buildManifest(
);
}
if (settings.scripts.some((script) => script.stage === 'page')) {
- scripts.push({ type: 'external', value: entryModules[PAGE_SCRIPT_ID] });
+ const src = entryModules[PAGE_SCRIPT_ID];
+
+ scripts.push({
+ type: 'external',
+ value: joinBase(src)
+ });
}
const links = sortedCSS(pageData).map((pth) => joinBase(pth));
diff --git a/packages/astro/test/fixtures/ssr-request/src/scripts/inject-script.js b/packages/astro/test/fixtures/ssr-request/src/scripts/inject-script.js
new file mode 100644
index 000000000..570612070
--- /dev/null
+++ b/packages/astro/test/fixtures/ssr-request/src/scripts/inject-script.js
@@ -0,0 +1 @@
+console.log("this is injected by injectScript");
diff --git a/packages/astro/test/ssr-request.test.js b/packages/astro/test/ssr-request.test.js
index 446a3e05d..08253a12a 100644
--- a/packages/astro/test/ssr-request.test.js
+++ b/packages/astro/test/ssr-request.test.js
@@ -13,6 +13,16 @@ describe('Using Astro.request in SSR', () => {
adapter: testAdapter(),
output: 'server',
base: '/subpath/',
+ integrations: [
+ {
+ name: 'inject-script',
+ hooks: {
+ 'astro:config:setup'({ injectScript }) {
+ injectScript('page', 'import "/src/scripts/inject-script.js";')
+ }
+ }
+ }
+ ],
vite: {
build: {
assetsInlineLimit: 0,
@@ -64,15 +74,17 @@ describe('Using Astro.request in SSR', () => {
const html = await response.text();
const $ = cheerioLoad(html);
- const scriptSrc = $('script').attr('src');
- expect(scriptSrc.startsWith('/subpath/')).to.equal(true);
+ for(const el of $('script')) {
+ const scriptSrc = $(el).attr('src');
+ expect(scriptSrc.startsWith('/subpath/')).to.equal(true);
- request = new Request('http://example.com' + scriptSrc);
- response = await app.render(request);
-
- expect(response.status).to.equal(200);
- const js = await response.text();
- expect(js).to.not.be.an('undefined');
+ request = new Request('http://example.com' + scriptSrc);
+ response = await app.render(request);
+
+ expect(response.status).to.equal(200);
+ const js = await response.text();
+ expect(js).to.not.be.an('undefined');
+ }
});
it('assets can be fetched', async () => {