question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document that vercel functions should be created as SvelteKit endpoints

See original GitHub issue

Hello team 👋, really enjoying the svelte-kit experience so far!

One thing I noticed is when using vercel’s serverless functions alongside a svelte-kit app there are a few nuances and unintended side effects, namely with client-side code not executing in local dev when svelte-kit is wrapped with vercel dev

minimal example repo: https://github.com/josefaidt/svelte-kit-vercel-local-issue

With vercel dev which executes svelte-kit dev -p $PORT and gives us the API routes image

With svelte-kit dev, no API routes image

When the application is deployed to vercel, everything appears fine! This seems to only affect local development.

I’ve since found a way around this behavior and I am fully aware svelte-kit is in beta so this will likely change, however I wanted to bring it up and reach out in case I am going against the grain with this setup.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

12reactions
dsegovia90commented, May 6, 2021

Hello, jumping in here to discuss a bit about serverless functions with sveltekit and vercel (and possibly others?).

I think there are 2 downsides of the current output of sveltekit endpoints functions with sveltekit. Currently endpoints hide behind the functions/render/index.js file, and from what I understand (see here), this creates only 1 serverless function, this issues are:

  1. Scalability: If you have 10 serverless functions with sveltekit, all 10 will hide behind the same serverless function endpoint in vercel (functions/render/index.js). If, say sveltekit function 1 of 10 has a high number of requests, the vercel serverless functions would need to copy and spin un another render/index.js. Which means it needs to clone all 10 sveltekit functions to run just that 1 endpoint again. This can slow down cold boot times and increase cost per function due to increased memory per vercel (AWS under the hood) function, see here.
  2. Memory/Size Limits: Functions could reach the memory or size limits if all functions are bundled together. See here.

Edit: There’s also the problem of cold boot time. I assume it would be slower to boot a 10 sveltekit function bundle, than just 1.

Let me know if I’m making the right assumptions, or if there is some code that I’m not seing that splits the render/index.js file into multiple vercel (AWS) functions.

2reactions
antonycommented, Mar 31, 2021

Just in order to manage expectations here, I didn’t consider vercel API functions at all when writing this adapter. It’s not that we can’t support them, they just aren’t something we expect to work right now. If they do, that’s pure chance.

After a chat with Leo from Vercel, the recommendation is to use Svelte Kit’s endpoints to write functions in, and not use the Vercel provided functionality - Vercel functions are really intended as helpers if your chosen framework doesn’t include a way to write serverless functions (or it is the blessed way to write serverless functions as it is in nextjs).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using SvelteKit 1.0 on Vercel
To create layouts in SvelteKit, add a file called +layout.svelte in the /routes folder. You can add whatever markup, styles, and behavior ...
Read more >
Endpoints – Vercel Docs
In this module, we will learn how to create server-side routes using SvelteKit endpoints.
Read more >
SvelteKit on Vercel
Vercel enables you to develop, preview, and ship every SvelteKit feature, without configuration. ... The fastest way to get started with Svelte on...
Read more >
Getting Started – Vercel Docs
In this video you will learn how to create a new SvelteKit project. We will explore the SvelteKit demo app to get familiar...
Read more >
Adapters – Vercel Docs
If we take a look at SvelteKit's documentation on adapters, we see it provides ... The vercel-adapter will then create a Vercel app,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found