News for hackers. Stuff that matters.
Re:Rich Harris joins Vercel to work on Svelte full time by ksdnjweusdnkl21 on Thursday November 11, 2021 @05:04PM (#29193787)
Seems like svelte is superior for not needing a key.
Re:Rich Harris joins Vercel to work on Svelte full time by s-lambert on Friday November 12, 2021 @03:12AM (#29197266)
Both Svelte[0] and React[1] are the same in this regard, the key is there as an optimization and isn't required in either framework. The only difference is that React's key is on the element whereas Svelte is as part of the each expression.

[0] https://svelte.dev/tutorial/keyed-each-blocks

[1] https://reactjs.org/docs/lists-and-keys.html

Re:Rich Harris joins Vercel to work on Svelte full time by winphone1974 on Thursday November 11, 2021 @05:45PM (#29194230)
The key is used by the shadow Dom for update performance; the is no shadow Dom in svelte
Re:Rich Harris joins Vercel to work on Svelte full time by alserio on Thursday November 11, 2021 @07:11PM (#29194894)
List diffing is done even in svelte at runtime. Keys are used the same way as any other frameworks or frontend libraries, virtual DOM or reactive.
Re:Rich Harris joins Vercel to work on Svelte full time by afavour on Thursday November 11, 2021 @06:44PM (#29194728)
And yet Svelte is faster than React in pretty much every benchmark I’ve seen.
Re:Rich Harris joins Vercel to work on Svelte full time by patrickthebold on Thursday November 11, 2021 @07:04PM (#29194849)
That makes sense though right? One would assume that shadow dom and dom would be slower than direct dom manipulation.
Re:Rich Harris joins Vercel to work on Svelte full time by thinkloop on Thursday November 11, 2021 @11:20PM (#29196269)
I'm not sure that's a fair assumption, one of the original sells of a shadow dom was that manipulting the dom directly is extremely slow, so doing as much work away from it is faster.
Re:Rich Harris joins Vercel to work on Svelte full time by ttfkam on Sunday November 14, 2021 @05:20PM (#29221274)
Because React's model requires tracking the entire DOM tree for changes and rewriting whole branches where a change is detected.

Svelte bypasses the whole problem for the most part. https://youtu.be/AdNJ3fydeao?t=247

Re:Rich Harris joins Vercel to work on Svelte full time by cphoover on Thursday November 11, 2021 @05:46PM (#29194236)
fair criticism I wonder how svelte optimizes for rerendering of long component lists. React uses keys to avoid rerendering the entire list.
Re:Rich Harris joins Vercel to work on Svelte full time by wruza on Friday November 12, 2021 @12:45AM (#29196621)
Keys are also essential to retaining an element identity, which is structurally more important than performance, because 1) code may have a reference to an element and think that it relates to some data, 2) an element may have an explicit state (like focused, animating, etc).

Keys are a hugely leaking abstraction, but are inevitable when you bridge a declarative immediate mode rendering into a stateful one.

Re:Rich Harris joins Vercel to work on Svelte full time by Mavvie on Thursday November 11, 2021 @06:51PM (#29194787)
I believe you can specify a key in Svelte as well, but perhaps it's used slightly differently than react.
Re:Rich Harris joins Vercel to work on Svelte full time by bdougherty on Thursday November 11, 2021 @07:55PM (#29195167)
Yeah it's not strictly necessary, but if you are updating the list (adding/removing especially), Svelte can know how to reuse elements properly if they are keyed. You also need keys for animations to work properly.