Skip to content
Draft
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/tidy-vercel-isr-pathnames.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-vercel': patch
---

fix: make Vercel ISR normalization redirects root-relative
27 changes: 22 additions & 5 deletions packages/adapter-vercel/files/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,27 @@ export default {
request = new Request(url, request);
}

return server.respond(request, {
getClientAddress() {
return /** @type {string} */ (request.headers.get('x-forwarded-for'));
}
});
return server
.respond(request, {
getClientAddress() {
return /** @type {string} */ (request.headers.get('x-forwarded-for'));
}
})
.then((response) => {
const location = response.headers.get('location');

if (
response.headers.has('x-sveltekit-normalize') &&
location &&
!location.startsWith('/') &&
pathname !== null
) {
const headers = new Headers(response.headers);
headers.set('location', new URL(`/${location}`, request.url).href);
return new Response(response.body, { status: response.status, headers });
}

return response;
});
}
};
4 changes: 2 additions & 2 deletions packages/adapter-vercel/test/apps/basic/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ test('ISR page with trailingSlash always loads without errors', async ({ page })
}
});

await page.goto('/isr-trailing-slash/');
await page.goto('/isr-trailing-slash-absolute/');

expect(new URL(page.url()).pathname).toBe('/isr-trailing-slash/');
expect(new URL(page.url()).pathname).toBe('/isr-trailing-slash-absolute/');
await expect(page.locator('h1')).toContainText('ISR Trailing Slash Page');
expect(errors).toEqual([]);
});
Expand Down
Loading