Assignments inside {#if} cause inconsistent state
Describe the bug
Assignments inside of an {#if} (which can be useful if the value being assigned is the return value of a function and it should be checked and used without calling the function twice) create an inconsistent state: The correct value is rendered, but event handlers see an old value.
To Reproduce Check this REPL: https://svelte.dev/repl/f24c001c7e284906a61d215b02dd0928?version=3.32.3
<script>
let name = 'foo';
</script>
{#if (name = 'bar')}
<button on:click={() => alert(name)}>I should alert "{name}"</button>
{/if}
Note that the alert says foo when clicking the button, despite the button text itself saying bar.
Expected behavior
Alert should say bar.
Severity Not causing any immediate issue for me, I can work around it.
The {#if} block is just resulting in (/*name*/ ctx[0] = "world") - presumably it should also generate an $$invalidate call like other expressions in the template do.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Since it has already been confirmed and labeled as bug, I don't think it makes sense to close this as stale just because it didn't make it out of the backlog yet...
It look like this bugs still here in the newest version. I'll take a crack at it, but I'm new so I would appreciate pointers if anyone knows where I should look.
Assignments and mutations inside the template are undefined behaviour, see https://github.com/sveltejs/svelte/issues/7295 and the linked issues there
Closing as duplicate of #3793