From b21038c193fd30351235a1b241a4a0aaf4e692f2 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Thu, 31 Aug 2023 18:34:50 +0100 Subject: [PATCH] fix: exclude redirects when running `functionPerRoute` (#8320) Co-authored-by: Nate Moore --- .changeset/gorgeous-dogs-speak.md | 5 +++ .../src/core/build/plugins/plugin-ssr.ts | 5 ++- .../ssr-split-manifest/astro.config.mjs | 10 ++--- .../ssr-split-manifest/src/pages/index.astro | 2 +- .../astro/test/ssr-split-manifest.test.js | 41 +++++++++++++++++++ 5 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 .changeset/gorgeous-dogs-speak.md diff --git a/.changeset/gorgeous-dogs-speak.md b/.changeset/gorgeous-dogs-speak.md new file mode 100644 index 000000000000..f479b86d8642 --- /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 44fc31155c21..33462050a709 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 171de39d9e24..e5e10bd9b7be 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 f189e711c19a..d8f84c6632a7 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 38a3233ee5e7..7df104e7616d 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; + }); + }); });