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:
parent
bc2bf460ea
commit
ae2a10e1a7
4 changed files with 26 additions and 2 deletions
5
.changeset/four-shoes-rule.md
Normal file
5
.changeset/four-shoes-rule.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@astrojs/vercel": patch
|
||||
---
|
||||
|
||||
Fixes an issue where functions were also created for prerendered routes with `functionPerRoute` enabled.
|
|
@ -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 }) => {
|
||||
|
|
12
packages/integrations/vercel/test/fixtures/functionPerRoute/src/pages/prerender.astro
vendored
Normal file
12
packages/integrations/vercel/test/fixtures/functionPerRoute/src/pages/prerender.astro
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
export const prerender = true;
|
||||
---
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Prerendered Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Prerendered Page</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -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
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue