Skip to content

Commit 3fdb3ad

Browse files
fix: prevent isr routes from handling remote function calls (#15085) (#15098)
* fix: prevent isr routes from handling remote function calls (#15085) * add changeset for observability changes
1 parent fd17209 commit 3fdb3ad

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

.changeset/brown-baboons-drop.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+
feat: show remote function calls under the /_app/remote route in observability

.changeset/full-points-battle.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: prevent isr routes from handling remote function calls

packages/adapter-vercel/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,31 @@ const plugin = function (defaults = {}) {
379379
);
380380
}
381381

382+
if (builder.config.kit.experimental.remoteFunctions) {
383+
// Ensure remote functions are always handled by the catchall route, which will be symlinked to /_app/remote.
384+
// This stops them from being affected by ISR config from other routes that match /[...rest] (ref: #15085)
385+
// and also makes them show as handled by `/_app/remote` in Vercel's observability.
386+
387+
const app_path = builder.getAppPath();
388+
const remote_dir = path.join(dirs.functions, app_path, 'remote'); // Usually .vercel/output/functions/_app/remote
389+
const remote_symlink_path = `${remote_dir}.func`;
390+
391+
// Handle remote functions with the catchall route as it won't have any ISR settings
392+
const target = path.join(dirs.functions, INTERNAL, 'catchall.func');
393+
394+
// Ensure the parent directory exists before symlinking
395+
builder.mkdirp(path.join(dirs.functions, app_path));
396+
397+
const relative = path.relative(path.dirname(remote_symlink_path), target);
398+
399+
fs.symlinkSync(relative, remote_symlink_path);
400+
401+
static_config.routes.push({
402+
src: `/${app_path}/remote/.+`,
403+
dest: `/${app_path}/remote` // Maps to /![-]/catchall via the symlink
404+
});
405+
}
406+
382407
for (const route of builder.routes) {
383408
if (is_prerendered(route)) continue;
384409

0 commit comments

Comments
 (0)