Skip to content

{@const} referencing let: slot prop causes "Cannot access '...' before initialization" (regression of #16585) #18119

Description

@shadow-identity

Describe the bug

{@const} inside a slot consumer that references a let: slot prop causes a runtime ReferenceError: Cannot access '<name>' before initialization (temporal dead zone). The issue reproduces on 5.55.1, so the fix from #16585 does not cover this variant.

The original issue (#16585) was reproduced with let:index used directly in a {@const} expression ({@const item = list[index]}). This variant fails when {@const} creates an object shorthand that captures the slot prop: {@const props = { row }} where row comes from let:row.

Reproduction

<!-- Parent.svelte -->
<script>
  export let data = [{ id: 1, label: 'A' }, { id: 2, label: 'B' }]
</script>

{#each data as row}
  <slot name="row" {row}></slot>
{/each}

<!-- Consumer.svelte -->
<Parent>
  <tr slot="row" let:row>
    {@const props = { row, onClick: () => console.log(row) }}
    <td>{props.row.label}</td>
  </tr>
</Parent>

Runtime error:

ReferenceError: Cannot access 'row' before initialization

REPL

Logs

System Info

System:
    OS: macOS 26.3.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 97.25 MB / 18.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.14.1 - /Users/xxx/.nvm/versions/node/v24.14.1/bin/node
    npm: 11.11.0 - /Users/xxx/.nvm/versions/node/v24.14.1/bin/npm
    pnpm: 10.33.0 - /Users/xxx/.nvm/versions/node/v24.14.1/bin/pnpm
  Browsers:
    Chrome: 147.0.7727.56
  npmPackages:
    svelte: ^5.55.1 => 5.55.1

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions