Skip to content

Commit

Permalink
fix: astro island urls missing assetsPrefix in SSR mode (#6862)
Browse files Browse the repository at this point in the history
Co-authored-by: Erika <[email protected]>
  • Loading branch information
jcdogo and Princesseuh authored Apr 17, 2023
1 parent 763b750 commit 1f26994
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/large-pens-rhyme.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 6 additions & 1 deletion packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -71,7 +72,11 @@ export class App {
return bundlePath;
}
default: {
return prependForwardSlash(joinPaths(manifest.base, bundlePath));
return createAssetLink(
bundlePath,
manifest.base,
manifest.assetsPrefix
);
}
}
},
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/core/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface SSRManifest {
routes: RouteInfo[];
site?: string;
base?: string;
assetsPrefix?: string;
markdown: MarkdownRenderingOptions;
pageMap: Map<ComponentPath, ComponentInstance>;
renderers: SSRLoadedRenderer[];
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/core/build/plugins/plugin-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 11 additions & 0 deletions packages/astro/test/astro-assets-prefix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1f26994

Please sign in to comment.