Skip to content

Svelte 5: incoherent {:else} in {#each} block #9908

@kuechlerm

Description

@kuechlerm

Describe the bug

The content of {:else} in an {#each} block where I iterate over Object.keys(data) is shown in some cases, but not in others.
I would expect:

  • do not update the content of {#each} when iterating over something like Object.keys(data) as it is not a $state / $derived
  • OR update the content (like it does now), but also show and hide the content of {:else}

To reproduce:

  • open REPL
  • click button to change second {#each} block

I have a local setup (that I cannot reproduce that quickly in a REPL) where I have a third constellation:
filter data -> no result -> only {:else} content shown -> remove filter -> data AND {:else} content visible

Workaround

{#each Object.keys(data) as key}
  // use key
{/each}

{#if Object.keys(data).length === 0}
  // use instead of {:each}
{/if) 

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE5VRXUvDMBT9KyH60EKxqG-xKygqDsQ9rPhiRLr0dovNktLcTkrpf5f0Y84PRCEkueecnHuStDSXCixlTy3V6RYoo5dlSQOKTekKuwOFQANqTV0Jh0RWVLLEmGuuOSpAAtsSGzIjxxZTBK_t_AuOE5mlmB5wKTsNyIqdBUSwcyccZblUCNWHME-VhZ7WHPNaC5RGEzTrtYKXQez5rSM5ytwbEJ-MCMe9X290McFjmi8xRrojoCz84IFV_d1if8ot_cR1FB48TpTJXZxspCVvpiosi0IHjLjTt0eQig1ZrF5B4EkBjfX6p_RJakkBzWCK7bRtmcs3osndfEmG8Thfzq_ub3pJ6Cw7l2RstqmmltcGLNEG-zh_SuOu-q8wD4vk1zRcR6sa0WhitFBSFLP205d2cdKX5LYvo3BQxzSgW5PJXEJGmfuN7rl7Bz-Q-uK6AgAA

Logs

No response

System Info

REPL

Severity

annoyance

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions