Skip to content

[Svelte 5] Components that are rendered as children remount when props change #9652

@mattjennings

Description

@mattjennings

Describe the bug

When a component is rendered as children in another component, if it references any props at the script top-level, it will remount when that prop changes.

<!-- App.svelte -->
<script>
    let count = $state(0)

    setInterval(() => count++, 100)
</script>

<Parent>
   <Child {count} />
<Parent />


<!-- Child.svelte -->
<script>
  const { count } = $props()
  
  console.log('mount', count)
</script>

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE71STU_DMAz9K1ZBaqdV67hO3QTixAGJ-7pDaV2IlI8qcSdQ1P9O0lThY2PixCnxy_Nz_GybdIyjSTZ7m8haYLJJ7vo-yRN6731gjsgJXWzUoBuPlKbRrKddJStioleawCr5qAZJI3RaCUhDUlpJgJnxVGuUND-vihCuIi8q3b8y3kbaFH1hOT2OBI2vBVu4NlQTZuuFf_Ai8zeybAHbHVgPVdQoaQiY4xukB0mojzWfKZPScpnDzdqrhASNNGgJ30ScDMdax3S2CPjoj9EFZfFpi_tNGTrc-buLQlu2CSYVE1wWkePsFaplHcM22ZAecMzjNALpbwOJdluYrYAzIwmG2NB8Do3_m6vhqM7SXqveZD8bslesi8TRi9hbd2tRRzRbONwWrBsvdTMZ8f_N-CkVhSMJ4ddQIKiBoJYtMEoNdOwNW8_xaorjiquXLN1PYgd4xk5pBOErpHmoFMZ_aeVOZM7k_7Zq59IHGQQuLN6p8YfxAwxgravgAwAA

Check the console

Logs

No response

System Info

System:
    OS: macOS 14.0
    CPU: (10) arm64 Apple M1 Max
    Memory: 384.41 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/Library/pnpm/node
    npm: 10.1.0 - /opt/homebrew/bin/npm
    pnpm: 8.8.0 - ~/Library/pnpm/pnpm
    bun: 1.0.0 - ~/.bun/bin/bun
  Browsers:
    Chrome: 118.0.5993.70
    Safari: 17.0
  npmPackages:
    svelte: 5.0.0-next.12 => 5.0.0-next.12

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    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