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:
parent
763b7500e5
commit
1f2699461d
5 changed files with 24 additions and 1 deletions
5
.changeset/large-pens-rhyme.md
Normal file
5
.changeset/large-pens-rhyme.md
Normal 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.
|
|
@ -21,6 +21,7 @@ import {
|
||||||
} from '../render/index.js';
|
} from '../render/index.js';
|
||||||
import { RouteCache } from '../render/route-cache.js';
|
import { RouteCache } from '../render/route-cache.js';
|
||||||
import {
|
import {
|
||||||
|
createAssetLink,
|
||||||
createLinkStylesheetElementSet,
|
createLinkStylesheetElementSet,
|
||||||
createModuleScriptElement,
|
createModuleScriptElement,
|
||||||
} from '../render/ssr-element.js';
|
} from '../render/ssr-element.js';
|
||||||
|
@ -71,7 +72,11 @@ export class App {
|
||||||
return bundlePath;
|
return bundlePath;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return prependForwardSlash(joinPaths(manifest.base, bundlePath));
|
return createAssetLink(
|
||||||
|
bundlePath,
|
||||||
|
manifest.base,
|
||||||
|
manifest.assetsPrefix
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -31,6 +31,7 @@ export interface SSRManifest {
|
||||||
routes: RouteInfo[];
|
routes: RouteInfo[];
|
||||||
site?: string;
|
site?: string;
|
||||||
base?: string;
|
base?: string;
|
||||||
|
assetsPrefix?: string;
|
||||||
markdown: MarkdownRenderingOptions;
|
markdown: MarkdownRenderingOptions;
|
||||||
pageMap: Map<ComponentPath, ComponentInstance>;
|
pageMap: Map<ComponentPath, ComponentInstance>;
|
||||||
renderers: SSRLoadedRenderer[];
|
renderers: SSRLoadedRenderer[];
|
||||||
|
|
|
@ -212,6 +212,7 @@ function buildManifest(
|
||||||
routes,
|
routes,
|
||||||
site: settings.config.site,
|
site: settings.config.site,
|
||||||
base: settings.config.base,
|
base: settings.config.base,
|
||||||
|
assetsPrefix: settings.config.build.assetsPrefix,
|
||||||
markdown: settings.config.markdown,
|
markdown: settings.config.markdown,
|
||||||
pageMap: null as any,
|
pageMap: null as any,
|
||||||
componentMetadata: Array.from(internals.componentMetadata),
|
componentMetadata: Array.from(internals.componentMetadata),
|
||||||
|
|
|
@ -98,6 +98,17 @@ describe('Assets Prefix - Server', () => {
|
||||||
expect(imgAsset.attr('src')).to.match(assetsPrefixRegex);
|
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 () => {
|
it('markdown image src start with assetsPrefix', async () => {
|
||||||
const request = new Request('http://example.com/custom-base/markdown/');
|
const request = new Request('http://example.com/custom-base/markdown/');
|
||||||
const response = await app.render(request);
|
const response = await app.render(request);
|
||||||
|
|
Loading…
Reference in a new issue