Kalan's Blog

Kalan 頭像照片,在淡水拍攝,淺藍背景

四零二曜日電子報上線啦!訂閱訂起來

Software Engineer / Taiwanese / Life in Fukuoka
This blog supports RSS feed (all content), you can click RSS icon or setup through third-party service. If there are special styles such as code syntax in the technical article, it is still recommended to browse to the original website for the best experience.

Current Theme light

我會把一些不成文的筆記或是最近的生活雜感放在短筆記,如果有興趣的話可以來看看唷!

Please notice that currenly most of posts are translated by AI automatically and might contain lots of confusion. I'll gradually translate the post ASAP

Svelte Notes (1) - No Silver Bullet

In the previous chapter, it was mentioned that I fell in love with Svelte. The core concept of Svelte is to "reduce runtime work through static analysis + compilation", which reduces the time for Virtual DOM diffing and a large amount of runtime work.

However, the path taken by Svelte also inevitably encounters some problems, the main one being that Svelte cannot do too much for you at runtime.

For example, this issue (Render slot fallback content when there's no content). When the slot content in Svelte is empty, it should render the fallback. However, because there is code like this inside:

<Box>
	{#if foo}
		something
	{/if}
</Box>

During static analysis, it can only detect that there is an if statement inside, and it will assume that there is content. As a result, the actual rendering will be blank instead of using the fallback.

Although it is called compilation, it still has some runtime mechanisms behind the scenes to track dependencies and updates. As long as the browser does not implement reactivity, the framework must handle this. Additionally, although the current compiler tries to minimize the generated code, as the functionality increases, the bundle size may gradually catch up. In larger projects, the difference may not be so obvious.

Another issue without Virtual DOM is testing. Virtual DOM provides an abstraction that makes it easy to implement according to the interface. Unlike React, which is very easy to test, this relates to both developer experience and user experience.

Furthermore, when writing code, I really dislike seeing statements like "XXX framework is awesome! Everything else is garbage". This kind of thinking not only hinders personal career and technical growth but is also detrimental.

Of course, this does not mean that everyone is equally great and that every framework or language is equally good. The choice of framework/language also represents your taste.

In the anime "Ping Pong", there is a line I really like:

It's creepy to bet your life on table tennis.

Although "creepy" may be a bit exaggerated, there is no framework that you must cling to. Your ability should depend on your mastery of the framework, rather than being controlled by it.

To summarize, if you want to introduce this framework into the company, you may need to observe it for a while. However, for quickly building small (or even medium-sized) projects, I personally find it very useful and can start development right away. In short, it is a framework that makes me excited, and I look forward to its future development.

Prev

Svelte — What made me meet you like this

Next

Rollup error encountered with Svelte with apollo-boost

If you found this article helpful, please consider buy me a drink ☕️ It'll make my ordinary day shine✨

Buy me a coffee