Reflections on Migrating My SaaS to SvelteKit
sveltekitsaas.com
sveltekitsaas.com
They should really be using the existing <script context="module"> syntax to have a context="server" portion instead of splitting the file out.
Heck, it could even just be an import for a server.ts file in the same root directory if people really liked the +whatever style of having the server code separated.
It feels especially redundant when you're building a static app or SPA. The sort of overly opinionated nonsense that put me off React and on to Svelte in the first place.
I've decided against making the switch to SvelteKit and instead rely on good old Svelte because I can have a /pages/Whatever.svelte encapsulates the structure and core logic of each view/page. It's clean, it's HTML-like, it works and more importantly, I can immediately wrap my head around it when coming back to the project after a period away.
I deeply love the guy, but I really think Rich should walk back this decision and default to the "whats the cleanest pattern that people can easily wrap their head around" approach.
That said… the one bit I can’t stand is every file having the same name. Working on 4 “+page.svelte” files at the same time breaks every dev environment I’ve ever liked (vscode, vim tabs). It seems to be fighting the tools and mental models I have.
Not ideal but not the biggest deal. And definitely not enough to trade Svelte in for something else.
I find the problem isn't necessarily the opinionated layout of Kit - I respect that they are trying to establish a sane pattern for frontenders to use. The problem is that this is locked down and enforced in the config and adaptors. Perhaps too much influence via way of the zeroconf web hosting services contributors work at.
Most problems I encounter, in particular of the SPA / making-a-quick-sketch kind, could be solved by more hackable control of the build system. Sometimes I'd like my routes in a single file, sometimes excluding some routes, sometimes a different pattern than +page.
If this breaks something, so what? You have the means to fix it or find a way. As it stands I find myself plugging away at an obtuse JSON object, or must make a my-weird-way-of-doing-things fork. Appeal to the maintainers and it reinforces a papa-knows-best attitude.
Just open it up, make the build system hackable - then see how people decide to use it.
He describes the drawbacks of mixing backend and frontend code in the same file in the Implicit DSLs section.
It's bonkers they decided to do this and not provide some sort of escape hatch.
Svelte's pattern for data binding (with the exception of the $: reactivity) is exceptionally idiomatic and as close to standard web as 2-way reactivity will ever be. Easy to get to grips with as a newbie and a breath of fresh air for someone with years of fe experience under their belt.
Svelte embodies the KISS principle and long may that last.
But some weird people like me enjoy JavaScript despite its downsides and find Ruby terrible.
Maybe its irrational but familiarity sometimes wins over level of idiomacy.
That being said, I definitely agree with the sentiment here that the file based routing is sub-optimal and I think the hurt goes up exponentially with the size of a project. I've also found that straying off the opinionated path even a little gets you in all sorts of trouble almost immediately. For me it was trying to add a SvelteKit app to an existing Nx codebase, did manage to make it work in the end luckily.
Btw, if anyone has found a good solution for creating an OpenAPI spec for SvelteKit server routes, let me know. :)
Not sure if you're talking about the article, but I'm the author and I love file-based routing. I think it's an exceptionally good idea that makes it so much easier to figure out where code lives. Haven't yet run into an issue that makes it "sub-optimal" like you said, but SvelteKit's node adapter does make it so you can set any routes you want with plain old Express.
Surely, this issue can not hand waved away by the entire team of two major web frameworks, while they are currently trying to establish directory based routing as a new paradigm?
1. Ecosystem - there's not a lot if any battle tested libraries for svelte at the moment, especially for data tables (tanstack does not have good performance and there's not much documentation for svelte), this will get better with time.
2. You have to do it the svelte way - whenever it's routing or using certain libraries that are vdom, it's usually not a painless experience.
With that said I still really love using svelte and honestly it saved me from giving up on web development.
:help setting-tabline
Low-level stuff; consolidating with some kind of project root directory concept and patterns would be convenient for such cases.
> :help setting-tabline
For VSCode users: Workbench > Editor: Label Format
Set to short will append the directory name right after the file name on the tabs, making it painless to work with the file structure.Yep. File-based routing is already in itself a questionable idea, but to me the whole +page thing is a deal breaker. I doubt they will change course on that but I hope they will add an alternative way of configuring routes, the request flow, etc.
SvelteKit has actually made me question if I should keep using Svelte at all in the future. Svelte has always been polarizing but I found myself agreeing with most of its strong opinions. With SvelteKit I've found myself in the opposite position where I disagree with pretty much everything.
I also miss some out of the box solutions like Devise (without using external services).
Instead of SvelteKit, I use Svelte with Fastify which offers a lot more for the backend.
In the past, I got tasked with an existing Next.js app to play nice with a Docusarus user guide they were building. I found that Docusaurus was very limiting in that environment, and I was forced to launch a separate Docusarus powered docs site under a different sub domain.
I’ve ported over the Docusaurus functionality into an open source Next.js project, complete with Markdown loading, Tailwind CSS, simple .env file configuration, and much more.
I fixed the Docusaurus problems that I mentioned above.
You can open the compiled svelte output and follow through the entire code path for updates in a few minutes.