fix: exclude redirects when running functionPerRoute (#8320)

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
Emanuele Stoppa 2023-08-31 18:34:50 +01:00 committed by GitHub
parent 5f3a44aeef
commit b21038c193
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 7 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Exclude redirects from split entry points

View file

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

View file

@ -1,7 +1,7 @@
import { defineConfig } from 'astro/config';
export default defineConfig({
build: {
split: true
},
output: "server"
})
output: "server",
redirects: {
"/redirect": "/"
}
})

View file

@ -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>

View file

@ -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('<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;
});
});
});