fix: exclude redirects when running functionPerRoute
(#8320)
Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
parent
5f3a44aeef
commit
b21038c193
5 changed files with 56 additions and 7 deletions
5
.changeset/gorgeous-dogs-speak.md
Normal file
5
.changeset/gorgeous-dogs-speak.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Exclude redirects from split entry points
|
|
@ -148,7 +148,10 @@ function vitePluginSSRSplit(
|
||||||
if (options.settings.config.build.split || functionPerRouteEnabled) {
|
if (options.settings.config.build.split || functionPerRouteEnabled) {
|
||||||
const inputs = new Set<string>();
|
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));
|
inputs.add(getVirtualModulePageNameFromPath(SPLIT_MODULE_ID, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { defineConfig } from 'astro/config';
|
import { defineConfig } from 'astro/config';
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
build: {
|
output: "server",
|
||||||
split: true
|
redirects: {
|
||||||
},
|
"/redirect": "/"
|
||||||
output: "server"
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { manifest } from 'astro:ssr-manifest';
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Testing</h1>
|
<h1>Testing index</h1>
|
||||||
<div id="assets" set:html={JSON.stringify([...manifest.assets])}></div>
|
<div id="assets" set:html={JSON.stringify([...manifest.assets])}></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -25,6 +25,11 @@ describe('astro:ssr-manifest, split', () => {
|
||||||
setRoutes(routes) {
|
setRoutes(routes) {
|
||||||
currentRoutes = routes;
|
currentRoutes = routes;
|
||||||
},
|
},
|
||||||
|
extendAdapter: {
|
||||||
|
adapterFeatures: {
|
||||||
|
functionPerRoute: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
// test suite was authored when inlineStylesheets defaulted to never
|
// test suite was authored when inlineStylesheets defaulted to never
|
||||||
build: { inlineStylesheets: 'never' },
|
build: { inlineStylesheets: 'never' },
|
||||||
|
@ -70,4 +75,40 @@ describe('astro:ssr-manifest, split', () => {
|
||||||
const html = await response.text();
|
const html = await response.text();
|
||||||
expect(html.includes('<title>Pre render me</title>')).to.be.true;
|
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;
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue