Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exclude redirects when running functionPerRoute #8320

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
});
});
});
Loading