Skip to content

svelte5: while binding this to none-existing property on desctructed object, svelte adds the property  #12636

@FoHoOV

Description

@FoHoOV

Describe the bug

In JS this:

const user = {name: "test"};
let {name, lastname} =  user;
lastname = "test2";
console.log(user);

will result in:

{name: "test"}

It will not create the lastname property on the user.

In svelte doing something similar:

<script>
	let users = $state([{name: "a"}]);
</script>


<!-- this creates the lastname on users[0] then assigns the value to it -->
<!-- which is not how js works -->
{#each users as {name, lastname}}
	<div bind:this={lastname}></div>
{/each}

<br>
{JSON.stringify(users)}

will create:

[{"name":"a","lastname":{"__svelte_meta":{"loc":{"file":"App.svelte","line":9,"column":1}}}}]

It seems that it doesn't work for other binds tho, just for bind:this. This is a breaking change (bind:value={lastname} works in svelte4 using the each block arguments to bind to), which I didn't find documented, maybe I'm blind, just pointing this out as well.

Reproduction

  1. openup this REPL
  2. see the output :D

Logs

No response

System Info

REPL 5.0.0-next.200

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