Skip to content

Commit

Permalink
fix: exclude redirects when running functionPerRoute (#8320)
Browse files Browse the repository at this point in the history
Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
  • Loading branch information
ematipico and natemoo-re authored Aug 31, 2023
1 parent 5f3a44a commit b21038c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-dogs-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Exclude redirects from split entry points
5 changes: 4 additions & 1 deletion packages/astro/src/core/build/plugins/plugin-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ function vitePluginSSRSplit(
if (options.settings.config.build.split || functionPerRouteEnabled) {
const inputs = new Set<string>();

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));
}

Expand Down
10 changes: 5 additions & 5 deletions packages/astro/test/fixtures/ssr-split-manifest/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from 'astro/config';
export default defineConfig({
build: {
split: true
},
output: "server"
})
output: "server",
redirects: {
"/redirect": "/"
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { manifest } from 'astro:ssr-manifest';
</style>
</head>
<body>
<h1>Testing</h1>
<h1>Testing index</h1>
<div id="assets" set:html={JSON.stringify([...manifest.assets])}></div>
</body>
</html>
41 changes: 41 additions & 0 deletions packages/astro/test/ssr-split-manifest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down Expand Up @@ -70,4 +75,40 @@ describe('astro:ssr-manifest, split', () => {
const html = await response.text();
expect(html.includes('<title>Pre render me</title>')).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('<title>Testing</title>')).to.be.true;
});
});
});

0 comments on commit b21038c

Please sign in to comment.