Code Monkey home page Code Monkey logo

Comments (8)

Rich-Harris avatar Rich-Harris commented on July 2, 2024 2

I tell a lie. HMR is a factor here, insofar as it's what accounts for the discrepancy between repros, but it's actually any effect inside an {#each ...} loop, not just the HMR effect. Remarkable that it wasn't surfaced sooner.

It was introduced in #11197 (demo), and is fixed in #11254.

from svelte.

Rich-Harris avatar Rich-Harris commented on July 2, 2024 1

I haven't figured out why, exactly, but this is related to HMR — if I disable it in the Vite config, things work as expected. That's why you can't reproduce it in the REPL

from svelte.

Thiagolino8 avatar Thiagolino8 commented on July 2, 2024

It doesn't happen in the production build, it probably has something to do with HMR

from svelte.

qupig avatar qupig commented on July 2, 2024

It doesn't happen in the production build, it probably has something to do with HMR

Yes, I can confirm this, which may explain why the issue is not reproduced in Svelte5-REPL.

from svelte.

gterras avatar gterras commented on July 2, 2024

Can you really use the value itself as a key? I've always thought it was not at all expected but it may be a relic from my Vue days since it isn't mentioned in the docs.

Anyway if you {#each array.entries() as [i, item] (i)} it starts working as expected.

from svelte.

Thiagolino8 avatar Thiagolino8 commented on July 2, 2024

Can you really use the value itself as a key? I've always thought it was not at all expected but it may be a relic from my Vue days since it isn't mentioned in the docs.

Yes you can
This has always been one of Svelte's differentiators.

The key can be any object, but strings and numbers are recommended since they allow identity to persist when the objects themselves change.

from svelte.

gterras avatar gterras commented on July 2, 2024

Yes you can

Yes although I have trouble seeing what's the under the hood difference in this case VS not using at all a key? Since the keys should also be modified along the values? Worth noting that both repros work as expected without key.

from svelte.

qupig avatar qupig commented on July 2, 2024

@gterras

Anyway if you {#each array.entries() as [i, item] (i)} it starts working as expected.

No, I tried that version and it produces the same effect.
Using the same value is just to simplify reproduction.

I can adapt this to a new reproduction of that syntax if you need it.

Here you go:
StackBlitz-svelte-5.0.0-next.108 (with k,v syntax)

from svelte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.