Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG Svelte 5: #key does not prevent $props() from changing if key is $derived #15697

Open
python273 opened this issue Apr 6, 2025 · 0 comments

Comments

@python273
Copy link

python273 commented Apr 6, 2025

Describe the bug

<script>
import Session from './Session.svelte'
let x = $state("qwe");
let sessionId = $derived(x + '$');
</script>

<button onclick={() => { x = ''+new Date().valueOf(); }}>Update</button>
{#key sessionId}
	<Session {sessionId}/>
{/key}

Session gets updated value before destruction.

Reproduction

If you click "Update" and look into console, Sessions logs updated sessionId in onDestroy:

https://svelte.dev/playground/hello-world?version=5.25.7#H4sIAAAAAAAAE3WRzU7DMBCEX8UyleKoVXJP00hIPcABcUCcCIcQb8Gqaxt7m7SK8u7YTegPtMcdz87ufu6oqjZAM_oAUmrSais5YcAFAo_pjK6EBEezt47i3gRfELw-dt0bk7gGJAbto3JwTa-1QlDoY2juaisMFqUSG6MtkhdwTmhFVlZvSJSkYz02R6WSgGRHFmTisEJgJf1uoaTxfHhxg_2RBwcHKxrgbEemJJpEwZOnx4G--Ngi-lla1VLU60XHYrIoSHfIj6KpgpYsw5A4aSq5hecVi-ek74tXw72cp0O_z-ru1rA_De99Oua_p3QnPQ3e1Hu9w4NA2CHN0G6hn90Aenn_JdR_b1fBljii7fyhS3Bo9Z70I-Aj1hIDvlp7q_IRB4BPFX4ltlJcb1iAV6If4PD8oIDZWG3caJgI5QzUyM6SZicwg-m4BhuBB3EI1xISqT9ZxAdHNCM3kkJPH__9US6a4my9PA3CJel3X1VCtkJxmq0q6aD_AcXJk9T1AgAA

Without $derived, onDestroy logs the correct value (though $inspect logs updated value):

https://svelte.dev/playground/hello-world?version=5.25.7#H4sIAAAAAAAAE3WRQU-DMBiG_0pTlwCRwJ0xEpMd9GA8GE_igdEPbVba2n4bLoT_biu4Dd2OfXm_p_0eeiqrFmhG70EIRTplBCMhMI7AIhrThguwNHvtKR607_nA5dPUndaJ3YNAn20qC5fyWkkEiQ5Dc1sbrrEoJW-1MkiewVquJGmMakmQpNN5Gg5KKQCJHcMHRlZkYbFCCEv62UFJo2Up8_QIdYfNDtHxlKwFr7erPozIqiD9jBEEtxI6svagKNlXYgdPTRgtyTAUL5q5OE9HjmP2N1s4nMYHdwvmv8_uT3nqu6nruoZbGuELaYZmB0N8Rd5817nAf98uSixx0ti7hddg0agDGSaZR4Uleom1clXpED8KHiv8SEwlmWpDL7FEd4HF84W8bG2UtlNhwaXVUGN4RopPYsbS8RnhJN6HI1wJSIR6DwM2NoKYXCH5mSH6-2cZ3xdnz8tTH8xNv7lTxUXHJaNZUwkLwzc9rcZv4QIAAA==

Logs

System Info

-

Severity

annoyance

@python273 python273 changed the title #key does not prevent $props() from changing if key is $derived BUG Svelte 5: #key does not prevent $props() from changing if key is $derived Apr 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant