Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svelte 5: each block with index causes error (works with svelte 4) #9636

Closed
amit13k opened this issue Nov 24, 2023 · 4 comments · Fixed by #9644
Closed

Svelte 5: each block with index causes error (works with svelte 4) #9636

amit13k opened this issue Nov 24, 2023 · 4 comments · Fixed by #9644

Comments

@amit13k
Copy link

amit13k commented Nov 24, 2023

Describe the bug

The following code examples (which work properly with svelte 4) produce errors with Svelte 5,

{#each ["a", "b"] as result, i (i)}
  <div>{result}</div>
{/each}
{#each ["a", "b"] as result, i (i)}
  <div>{i}</div>
{/each}
<!-- This (with only one element) doesn't produce any errors. -->
{#each ["a"] as result, i (i)}
  <div>{result}</div>
{/each}

Reproduction

Example 1 Svelte 5 REPL

Example 2 Svelte 5 REPL

Logs

No response

System Info

System:
    OS: macOS 14.2
    CPU: (12) arm64 Apple M2 Pro
    Memory: 213.45 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.2.0 - /opt/homebrew/bin/node
    Yarn: 1.22.21 - /opt/homebrew/bin/yarn
    npm: 6.14.16 - /opt/homebrew/bin/npm
    pnpm: 8.10.5 - /opt/homebrew/bin/pnpm
    bun: 1.0.3 - ~/.bun/bin/bun
  Browsers:
    Chrome: 119.0.6045.159
    Chrome Canary: 121.0.6145.0
    Safari: 17.2

Severity

annoyance

@AgarwalPragy
Copy link

AgarwalPragy commented Nov 24, 2023

Duplicate issues:
#9629
#9408

@brunnerh
Copy link
Member

@AgarwalPragy One of those is this very issue, the other does not look like it has anything to do with this.

Though on #9408 it claims to be linked from this. Something bugged here?

Anyway, I explained the issue over there:

This is a dev mode only issue. The production build is exactly the same (the implemented fix turns it into an indexed each).

This is currently still falsely added in dev mode:

$.validate_each_keys(() => [1, 2, 3], (item) => {
  return $.get(i);
});

@AgarwalPragy
Copy link

My bad. Updated.

@brunnerh
Copy link
Member

Issue of first REPL should now be fixed via #9641.

Issue of second REPL still exists. Somehow adding the key term changes how i is being treated:

- text.nodeValue = $.stringify(i);
+ /* Update */
+ $.text_effect(text, () => $.get(i));

...and while I was writing that #9644 has been created 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants