From 1f2699461d4cdcc8007ae47ebff74ace62eee058 Mon Sep 17 00:00:00 2001 From: jcdogo <70533701+jcdogo@users.noreply.github.com> Date: Sun, 16 Apr 2023 23:35:48 -0700 Subject: [PATCH] fix: astro island urls missing assetsPrefix in SSR mode (#6862) Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com> --- .changeset/large-pens-rhyme.md | 5 +++++ packages/astro/src/core/app/index.ts | 7 ++++++- packages/astro/src/core/app/types.ts | 1 + packages/astro/src/core/build/plugins/plugin-ssr.ts | 1 + packages/astro/test/astro-assets-prefix.test.js | 11 +++++++++++ 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 .changeset/large-pens-rhyme.md diff --git a/.changeset/large-pens-rhyme.md b/.changeset/large-pens-rhyme.md new file mode 100644 index 0000000000..b5faeee49b --- /dev/null +++ b/.changeset/large-pens-rhyme.md @@ -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. diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 328769f2a5..69668dbcf8 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -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 + ); } } }, diff --git a/packages/astro/src/core/app/types.ts b/packages/astro/src/core/app/types.ts index b7b5fa45a9..ab91c13ca3 100644 --- a/packages/astro/src/core/app/types.ts +++ b/packages/astro/src/core/app/types.ts @@ -31,6 +31,7 @@ export interface SSRManifest { routes: RouteInfo[]; site?: string; base?: string; + assetsPrefix?: string; markdown: MarkdownRenderingOptions; pageMap: Map; renderers: SSRLoadedRenderer[]; diff --git a/packages/astro/src/core/build/plugins/plugin-ssr.ts b/packages/astro/src/core/build/plugins/plugin-ssr.ts index d3776cd518..837c72b721 100644 --- a/packages/astro/src/core/build/plugins/plugin-ssr.ts +++ b/packages/astro/src/core/build/plugins/plugin-ssr.ts @@ -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), diff --git a/packages/astro/test/astro-assets-prefix.test.js b/packages/astro/test/astro-assets-prefix.test.js index 7cbfe274cf..be80d46011 100644 --- a/packages/astro/test/astro-assets-prefix.test.js +++ b/packages/astro/test/astro-assets-prefix.test.js @@ -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);