Include base in 'page' stage injected scripts (#5572)
* Include base in 'page' stage injected scripts * Add changeset
This commit is contained in:
parent
50ecb3005d
commit
b2f0210c40
4 changed files with 32 additions and 9 deletions
5
.changeset/few-days-refuse.md
Normal file
5
.changeset/few-days-refuse.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Include base in 'page' stage injected scripts
|
|
@ -146,7 +146,12 @@ function buildManifest(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (settings.scripts.some((script) => script.stage === 'page')) {
|
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));
|
const links = sortedCSS(pageData).map((pth) => joinBase(pth));
|
||||||
|
|
1
packages/astro/test/fixtures/ssr-request/src/scripts/inject-script.js
vendored
Normal file
1
packages/astro/test/fixtures/ssr-request/src/scripts/inject-script.js
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
console.log("this is injected by injectScript");
|
|
@ -13,6 +13,16 @@ describe('Using Astro.request in SSR', () => {
|
||||||
adapter: testAdapter(),
|
adapter: testAdapter(),
|
||||||
output: 'server',
|
output: 'server',
|
||||||
base: '/subpath/',
|
base: '/subpath/',
|
||||||
|
integrations: [
|
||||||
|
{
|
||||||
|
name: 'inject-script',
|
||||||
|
hooks: {
|
||||||
|
'astro:config:setup'({ injectScript }) {
|
||||||
|
injectScript('page', 'import "/src/scripts/inject-script.js";')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
vite: {
|
vite: {
|
||||||
build: {
|
build: {
|
||||||
assetsInlineLimit: 0,
|
assetsInlineLimit: 0,
|
||||||
|
@ -64,15 +74,17 @@ describe('Using Astro.request in SSR', () => {
|
||||||
const html = await response.text();
|
const html = await response.text();
|
||||||
const $ = cheerioLoad(html);
|
const $ = cheerioLoad(html);
|
||||||
|
|
||||||
const scriptSrc = $('script').attr('src');
|
for(const el of $('script')) {
|
||||||
expect(scriptSrc.startsWith('/subpath/')).to.equal(true);
|
const scriptSrc = $(el).attr('src');
|
||||||
|
expect(scriptSrc.startsWith('/subpath/')).to.equal(true);
|
||||||
|
|
||||||
request = new Request('http://example.com' + scriptSrc);
|
request = new Request('http://example.com' + scriptSrc);
|
||||||
response = await app.render(request);
|
response = await app.render(request);
|
||||||
|
|
||||||
expect(response.status).to.equal(200);
|
expect(response.status).to.equal(200);
|
||||||
const js = await response.text();
|
const js = await response.text();
|
||||||
expect(js).to.not.be.an('undefined');
|
expect(js).to.not.be.an('undefined');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('assets can be fetched', async () => {
|
it('assets can be fetched', async () => {
|
||||||
|
|
Loading…
Reference in a new issue