Skip to content

Commit

Permalink
Fix an issue where Vercel adapter may create functions for prerendere…
Browse files Browse the repository at this point in the history
…d 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>
  • Loading branch information
mingjunlu and lilnasy authored Feb 26, 2024
1 parent bc2bf46 commit ae2a10e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-shoes-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/vercel": patch
---

Fixes an issue where functions were also created for prerendered routes with `functionPerRoute` enabled.
4 changes: 3 additions & 1 deletion packages/integrations/vercel/src/serverless/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
export const prerender = true;
---

<html>
<head>
<title>Prerendered Page</title>
</head>
<body>
<h1>Prerendered Page</h1>
</body>
</html>
7 changes: 6 additions & 1 deletion packages/integrations/vercel/test/split.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});
});

0 comments on commit ae2a10e

Please sign in to comment.