diff --git a/.changeset/gorgeous-dogs-speak.md b/.changeset/gorgeous-dogs-speak.md new file mode 100644 index 000000000..f479b86d8 --- /dev/null +++ b/.changeset/gorgeous-dogs-speak.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Exclude redirects from split entry points diff --git a/packages/astro/src/core/build/plugins/plugin-ssr.ts b/packages/astro/src/core/build/plugins/plugin-ssr.ts index 44fc31155..33462050a 100644 --- a/packages/astro/src/core/build/plugins/plugin-ssr.ts +++ b/packages/astro/src/core/build/plugins/plugin-ssr.ts @@ -148,7 +148,10 @@ function vitePluginSSRSplit( if (options.settings.config.build.split || functionPerRouteEnabled) { const inputs = new Set(); - for (const path of Object.keys(options.allPages)) { + for (const [path, pageData] of Object.entries(options.allPages)) { + if (routeIsRedirect(pageData.route)) { + continue; + } inputs.add(getVirtualModulePageNameFromPath(SPLIT_MODULE_ID, path)); } diff --git a/packages/astro/test/fixtures/ssr-split-manifest/astro.config.mjs b/packages/astro/test/fixtures/ssr-split-manifest/astro.config.mjs index 171de39d9..e5e10bd9b 100644 --- a/packages/astro/test/fixtures/ssr-split-manifest/astro.config.mjs +++ b/packages/astro/test/fixtures/ssr-split-manifest/astro.config.mjs @@ -1,7 +1,7 @@ import { defineConfig } from 'astro/config'; export default defineConfig({ - build: { - split: true - }, - output: "server" -}) \ No newline at end of file + output: "server", + redirects: { + "/redirect": "/" + } +}) diff --git a/packages/astro/test/fixtures/ssr-split-manifest/src/pages/index.astro b/packages/astro/test/fixtures/ssr-split-manifest/src/pages/index.astro index f189e711c..d8f84c663 100644 --- a/packages/astro/test/fixtures/ssr-split-manifest/src/pages/index.astro +++ b/packages/astro/test/fixtures/ssr-split-manifest/src/pages/index.astro @@ -11,7 +11,7 @@ import { manifest } from 'astro:ssr-manifest'; -

Testing

+

Testing index

diff --git a/packages/astro/test/ssr-split-manifest.test.js b/packages/astro/test/ssr-split-manifest.test.js index 38a3233ee..7df104e76 100644 --- a/packages/astro/test/ssr-split-manifest.test.js +++ b/packages/astro/test/ssr-split-manifest.test.js @@ -25,6 +25,11 @@ describe('astro:ssr-manifest, split', () => { setRoutes(routes) { currentRoutes = routes; }, + extendAdapter: { + adapterFeatures: { + functionPerRoute: true, + }, + }, }), // test suite was authored when inlineStylesheets defaulted to never build: { inlineStylesheets: 'never' }, @@ -70,4 +75,40 @@ describe('astro:ssr-manifest, split', () => { const html = await response.text(); expect(html.includes('Pre render me')).to.be.true; }); + + describe('when function per route is enabled', async () => { + before(async () => { + fixture = await loadFixture({ + root: './fixtures/ssr-split-manifest/', + output: 'server', + adapter: testAdapter({ + setEntryPoints(entries) { + if (entries) { + entryPoints = entries; + } + }, + setRoutes(routes) { + currentRoutes = routes; + }, + extendAdapter: { + adapterFeatures: { + functionPerRoute: true, + }, + }, + }), + // test suite was authored when inlineStylesheets defaulted to never + build: { inlineStylesheets: 'never' }, + }); + await fixture.build(); + }); + it('should correctly build, and not create a "uses" entry point', async () => { + const pagePath = 'src/pages/index.astro'; + const app = await fixture.loadEntryPoint(pagePath, currentRoutes); + const request = new Request('http://example.com/'); + const response = await app.render(request); + const html = await response.text(); + console.log(html); + expect(html.includes('Testing')).to.be.true; + }); + }); });