Skip to content

Commit c67da8a

Browse files
Merge commit from fork
* fix: 404 for immutable assets that don't match static files * how did i not see this * woot
1 parent 3e607b3 commit c67da8a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

.changeset/eighty-rabbits-sit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-vercel': patch
3+
---
4+
5+
fix: 404 for immutable assets that don't match static files

packages/adapter-vercel/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,19 @@ function static_vercel_config(builder, config, dir) {
616616
}
617617

618618
const routes = [
619+
// Strip any user-supplied __pathname query parameter; SvelteKit reserves
620+
// this for ISR handlers
621+
{
622+
src: '.*',
623+
continue: true,
624+
transforms: [
625+
{
626+
type: 'request.query',
627+
op: 'delete',
628+
target: { key: '__pathname' }
629+
}
630+
]
631+
},
619632
...prerendered_redirects,
620633
{
621634
src: `/${builder.getAppPath()}/immutable/.+`,
@@ -666,6 +679,16 @@ function static_vercel_config(builder, config, dir) {
666679
handle: 'filesystem'
667680
});
668681

682+
// Prevent incorrect caching: if a request to /_app/immutable/* doesn't match
683+
// a static file, return 404 instead of falling through to dynamic routes.
684+
// Otherwise, we could accidentally immutably cache dynamic content served
685+
// by the fallback function.
686+
routes.push({
687+
src: `/${builder.getAppPath()}/immutable/.+`,
688+
status: 404,
689+
continue: false
690+
});
691+
669692
return {
670693
version: 3,
671694
routes,

0 commit comments

Comments
 (0)