[breaking] Analysing code during build #7716
Replies: 8 comments 19 replies
-
I guess most people probably set up their DB connections as part of |
Beta Was this translation helpful? Give feedback.
-
I'm from the last ones who argued about this issue, and it kinda seems it isn't relevant to me anymore. Because of what I currently do now is this:
I.e. I'm completely OK if you remove option This will definitely break some other people's apps who still try to make old-fashioned SPA instead of MPA, when they update, - but you can probably show them a clean error that this setting is not supported anymore, and give link why. Guys, just don't do SPA, heck... Make MPA. Preferably, with Svelte 👍 |
Beta Was this translation helpful? Give feedback.
-
Exporting config from code vs making another filenaming convention is a good idea. I'd argue all configuration should be exported this way vs any filenaming convention in order to provide an escape hatch for folks who have a hard time swallowing the conventions. One of the main arguments that was used against doing this to identify which layout should be used for a page, (vs using a filename convention) was that you'd have to parse and execute the page in order to determine the layout. Maintainers didn't want to use a complex regex to identify pages. So they put it in the filename. Seems like this pattern is resurfacing with config per page. If parsing and executing pages at build time is no longer a dealbreaker, and you implement config for pages as an export, you may get closer to being able to abstract the routing config away from filenames. Hope that's helpful |
Beta Was this translation helpful? Give feedback.
-
I was wondering at first if this might break "Truer SPA Mode" (#1650), but since the options would all be in |
Beta Was this translation helpful? Give feedback.
-
This is a way bad idea. If SvelteKit can't analyze a piece of code without running it, that's a sure sign that it has overstepped its remit. |
Beta Was this translation helpful? Give feedback.
-
One idea might be to name it in the file, such as |
Beta Was this translation helpful? Give feedback.
-
I love how ambitious you are on behalf of Sveltekit. It would be a killer feature in the not-so-distant future running edge functions, communicating with some edge-deployed database ✨ What about the complexity of different providers? What if Vercel workers are different than Cloudflare workers? Would be 10/10 awesome if I hypothetically changed the adapter from Vercel to Cloudflare workers, and then got a warning/error from the adapter saying something like Cloudflare edge runtime does not support this feature XYZ. |
Beta Was this translation helpful? Give feedback.
-
For my testing, I like to build some projects locally with prerendering disabled (for debugging prerendering issues and also for faster build time). Therefore, removing the options to (temporary) disable prerendering is not preferable for me, and I believe also for other people. I do agree that this configuration in |
Beta Was this translation helpful? Give feedback.
-
PR: #7762
When you
build
your app, SvelteKit will analyse your entry points (+page.js
,+page.server.js
and+server.js
) during prerendering, so that it can know which ones can be excluded from your server (i.e. there's no point including code to render your/about
page on-demand if that page is already prerendered).In future, it's quite likely that we'll want to add more information to those entry points. For example, we might want some pages to be rendered at the edge, while other pages are rendered in a specific region near your database; some endpoints might run in a worker-type environment, whereas others need to run in a Lambda so that they can use native Node modules. Today, these things are only configurable on an app-wide level, which only goes so far.
An example of how this could look:
The best way to express that configuration is almost certainly as an exported variable that's read during build (rather than adding JSON configuration or doing some funky static analysis stuff — we want to be able to use environment variables and imports and type safety and everything else). That means doing the same thing for
config
as we currently do forprerender
— loading each entry point and reading its exports. The config would then be passed to adapters so that they can validate it and prep the deployment accordingly.(It could also be used to — for example — ensure that you weren't importing Node modules into places where they can't be used.)
Here's the wrinkle: to do this, we need to run your code as soon as we've built it. We don't need to actually render anything (unless it's marked as prerenderable), but we do need to import and evaluate your entry points, which could (for example) result in db connections being set up.
Today, you can disable that with
config.kit.prerender.enabled = false
. But if we're leaning more in this direction, we would probably need to get rid of that option.We should also change the name of the import:
In theory, it should be possible to disable any problematic code with an
if (!building) {...}
block. But in the past, there's been some confusion around this. So I'd love to get a better sense from people as to whether this is something we can realistically do, or if there are problems we're not foreseeing?Beta Was this translation helpful? Give feedback.
All reactions