tobiasBora
tobiasBora

Reputation: 2432

Why aren't rune enabled transparently with the old syntax, and when not to use them?

Svelte 5 introduce runes, and recommends now to write:

let foo = $state(42);

instead of the elegant

let foo = 42;

I can understand why it makes sense in React… but since svelte is a compiler, why can't it automatically compile let foo = 42; into its rune equivalent? I guess that because sometimes one might NOT want to assign something via a rune… but it which case would a standard let be better than a "rune let"?

Upvotes: 0

Views: 249

Answers (1)

brunnerh
brunnerh

Reputation: 185180

There are multiple reasons:

  • The added reactivity has a certain amount of overhead (it creates a signal internally).
  • For objects, it wraps the object in a Proxy, which can also cause certain issues and will impact performance since every access goes though said proxy.
  • It is less explicit without $state. Svelte 5 moves away from all the "magic".
    See this point in the tenets:

    Magical, not magic

    There's a subtle line between something feeling magical, and something feeling like magic. We want Svelte to feel magical — we want you to feel like a wizard when you're writing Svelte code. Historically I think Svelte went too far into magic territory, where it's not 100% clear why things work a certain way, and that's something that we're rectifying with Svelte 5.

Upvotes: 1

Related Questions