0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-27 22:19:04 -05:00

Fix an issue where Vercel adapter may create functions for prerendered routes (#10231)

* fix: fix an issue where Vercel adapter may create functions for prerendered routes

* test: update test cases in `split.test.js`

* chore: add changeset

* refactor: apply suggested changes from code review

* Apply suggestions from code review

---------

Co-authored-by: Arsh <69170106+lilnasy@users.noreply.github.com>
This commit is contained in:
Ming-jun Lu 2024-02-26 21:28:49 +08:00 committed by GitHub
parent bc2bf460ea
commit ae2a10e1a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 26 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
"@astrojs/vercel": patch
---
Fixes an issue where functions were also created for prerendered routes with `functionPerRoute` enabled.

View file

@ -288,7 +288,9 @@ export default function vercelServerless({
}
},
'astro:build:ssr': async ({ entryPoints, middlewareEntryPoint }) => {
_entryPoints = entryPoints;
_entryPoints = new Map(
Array.from(entryPoints).filter(([routeData]) => !routeData.prerender)
);
_middlewareEntryPoint = middlewareEntryPoint;
},
'astro:build:done': async ({ routes, logger }) => {

View file

@ -0,0 +1,12 @@
---
export const prerender = true;
---
<html>
<head>
<title>Prerendered Page</title>
</head>
<body>
<h1>Prerendered Page</h1>
</body>
</html>

View file

@ -14,14 +14,19 @@ describe('build: split', () => {
await fixture.build();
});
it('creates separate functions for each page', async () => {
it('creates separate functions for non-prerendered pages', async () => {
const files = await fixture.readdir('../.vercel/output/functions/');
assert.equal(files.length, 3);
assert.equal(files.includes('prerender.astro.func'), false);
});
it('creates the route definitions in the config.json', async () => {
const json = await fixture.readFile('../.vercel/output/config.json');
const config = JSON.parse(json);
assert.equal(config.routes.length, 5);
assert.equal(
config.routes.some((route) => route.dest === 'prerender.astro'),
false
);
});
});