Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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/shiny-needles-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-vercel': patch
---

Fix `edge:true, split: true` build error for root routes when deploying to Vercel
19 changes: 18 additions & 1 deletion packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ async function v3(builder, external, edge, split) {
.slice(1, -2) // remove leading / and trailing $/
.replace(/\\\//g, '/')}(?:/__data.json)?$`; // TODO adding /__data.json is a temporary workaround — those endpoints should be treated as distinct routes

await generate_function(route.id, src, entry.generateManifest);
await generate_function(createValidFunctionName(route.id), src, entry.generateManifest);
}
};
});
Expand Down Expand Up @@ -385,3 +385,20 @@ function write(file, data) {

writeFileSync(file, data);
}

/**
* Make all root routes be called `index`:
*
* @example
* ```js
* createValidFunctionName("") // "index"
* createValidFunctionName("nested") // "nested"
* createValidFunctionName("nested/") // "nested/index"
* ```
*
* @param {string} routeId
* @returns {string} route id that is a valid function name
*/
function createValidFunctionName(routeId) {
return routeId.replace(/(\/|^)$/, '$1index');
}