fix: astro island urls missing assetsPrefix in SSR mode (#6862)

Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
This commit is contained in:
jcdogo 2023-04-16 23:35:48 -07:00 committed by GitHub
parent 763b7500e5
commit 1f2699461d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes bug with assetsPrefix not being prepended to component-url and renderer-url in astro islands when using SSR mode.

View file

@ -21,6 +21,7 @@ import {
} from '../render/index.js';
import { RouteCache } from '../render/route-cache.js';
import {
createAssetLink,
createLinkStylesheetElementSet,
createModuleScriptElement,
} from '../render/ssr-element.js';
@ -71,7 +72,11 @@ export class App {
return bundlePath;
}
default: {
return prependForwardSlash(joinPaths(manifest.base, bundlePath));
return createAssetLink(
bundlePath,
manifest.base,
manifest.assetsPrefix
);
}
}
},

View file

@ -31,6 +31,7 @@ export interface SSRManifest {
routes: RouteInfo[];
site?: string;
base?: string;
assetsPrefix?: string;
markdown: MarkdownRenderingOptions;
pageMap: Map<ComponentPath, ComponentInstance>;
renderers: SSRLoadedRenderer[];

View file

@ -212,6 +212,7 @@ function buildManifest(
routes,
site: settings.config.site,
base: settings.config.base,
assetsPrefix: settings.config.build.assetsPrefix,
markdown: settings.config.markdown,
pageMap: null as any,
componentMetadata: Array.from(internals.componentMetadata),

View file

@ -98,6 +98,17 @@ describe('Assets Prefix - Server', () => {
expect(imgAsset.attr('src')).to.match(assetsPrefixRegex);
});
it('react component astro-island should import from assetsPrefix', async () => {
const request = new Request('http://example.com/custom-base/');
const response = await app.render(request);
expect(response.status).to.equal(200);
const html = await response.text();
const $ = cheerio.load(html);
const island = $('astro-island');
expect(island.attr('component-url')).to.match(assetsPrefixRegex);
expect(island.attr('renderer-url')).to.match(assetsPrefixRegex);
});
it('markdown image src start with assetsPrefix', async () => {
const request = new Request('http://example.com/custom-base/markdown/');
const response = await app.render(request);