David Rodenas PhD
2 min readDec 30, 2022

--

Be careful with Svelte because its change detection algorithm is wrong, and it can create inconsistencies. I have here a small example:

https://twitter.com/drpicox/status/1496461071334490112

There is no magic in programming, which means that somehow changes has to be propagated. For example, React does not expect any kind of magic, like Angular o Vue, because React is a library, it asks for direct notification that the state has changed (that is the useState to declare something as state, and the setState). Angular uses a watch mechanism that compares whole values every time that something happens. Vue uses proxies to catch changes.

In the case of Svelte, it basically transpiles the code, and adds part of the “React of creating the useState and making the setState” (not this exact code, but the same behavior). To make it right, the transpiler detects all the changes that could happen to the state variable, and replaces all the access by the setState. The problem, is that there is no magic, and sometimes, the compiler cannot catch everything.

And that is the trouble of Svelte. It is nice to write articles, but in real applications, it is dangerous. A non-expert programmer does not know what happens under the hood. So, he can break the application really quickly (just by using third-party libraries) and start having weird problems that nobody understand.

--

--

David Rodenas PhD
David Rodenas PhD

Written by David Rodenas PhD

Passionate software engineer & storyteller. Sharing knowledge to advance our skills. Join me on a journey of discovery in the world of software engineering.

No responses yet