Skip to content

undefined is not iterable when using default, named and props with slots #5684

@tqwewe

Description

@tqwewe

Describe the bug
When destructuring slot props with named slots, svelte errors with undefined is not iterable.

Eg:

<List {items} let:item={{ name }}>
  <div>{name}</div>

  <div slot="custom-slot">Custom slot</div>
</List>

Logs

message: "Uncaught (in promise): undefined is not iterable (cannot read property Symbol(Symbol.iterator))"
stack: TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
at Array.List.props.$$slots.header.item (eval at handle_message (about:srcdoc:13:8), <anonymous>:1036:11)
at get_slot_context (eval at handle_message (about:srcdoc:13:8), <anonymous>:65:56)
at create_slot (eval at handle_message (about:srcdoc:13:8), <anonymous>:59:30)
at create_fragment (eval at handle_message (about:srcdoc:13:8), <anonymous>:766:26)
at init (eval at handle_message (about:srcdoc:13:8), <anonymous>:549:41)
at new List (eval at handle_message (about:srcdoc:13:8), <anonymous>:936:7)
at create_if_block (eval at handle_message (about:srcdoc:13:8), <anonymous>:1020:13)

To Reproduce
Playgroun: https://svelte.dev/repl/9f24b8378c234f06ae837fdfdb1373fa?version=3.29.7

Expected behavior
There should be no error when destructuring the named slot with let:item={[item]}

Stacktraces

Uncaught (in promise): undefined is not iterable (cannot read property Symbol(Symbol.iterator))

TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
at Array.List.props.$$slots.header.item (eval at handle_message (about:srcdoc:13:8), :1036:11)
at get_slot_context (eval at handle_message (about:srcdoc:13:8), :65:56)
at create_slot (eval at handle_message (about:srcdoc:13:8), :59:30)
at create_fragment (eval at handle_message (about:srcdoc:13:8), :766:26)
at init (eval at handle_message (about:srcdoc:13:8), :549:41)
at new List (eval at handle_message (about:srcdoc:13:8), :936:7)
at create_if_block (eval at handle_message (about:srcdoc:13:8), :1020:13)

Information about your Svelte project:

  • Your browser and the version: Chrome 86.0.4240.198 (Official Build) (x86_64)

  • Your operating system: OS X 10

  • Svelte version: 3.29.7

  • Bundler: Rollup

Severity
Temporary fix available if you don't do any object/array destructuring but it would be nice to have this fixed so I can clean my code and have my variables named properly.

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions