You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using bind:this to get a reference to a mounted component <svelte:component this={someComponent} bind:this={someRef} /> and then switching the value of someComponent (causing a remount), someRef will be updated twice. first being set to the new mounted component and then afterwards to null.
It only seems to happen if the old components does not export any functions but the new component does.
This happens only in production builds (vite build), not in dev build (vite dev)
Try to use the select box to first select component D, which does not export any functions, then switch back to component A. See the browser console to observe how the null value is logged last.
@paoloricciuti on discord helped me to track down this issue. The core issue seems to be that I am using a $state.frozen state with a get/set wrapper for the bind:this value. Using a simple $state() solves the issue. But it would be great if $state.frozen would also work.
Describe the bug
When using
bind:this
to get a reference to a mounted component<svelte:component this={someComponent} bind:this={someRef} />
and then switching the value ofsomeComponent
(causing a remount),someRef
will be updated twice. first being set to the new mounted component and then afterwards to null.It only seems to happen if the old components does not export any functions but the new component does.
This happens only in production builds (
vite build
), not in dev build (vite dev
)For me it seems like this happens to late (or should not happen at all?):
https://github.com/sveltejs/svelte/blob/main/packages/svelte/src/internal/client/dom/elements/bindings/this.js#L54
Reproduction
This is an example where it happens. BUT NOT in the online editor version, only when running
vite build
locally:https://svelte-5-preview.vercel.app/#H4sIAAAAAAAACr1UTY-bMBD9KxatFNAiWG3VC0uQQk57qtRDL5s9GGdQ3AWDbBMFIf_32piP7JKN0g_1QGJmnt943jzTOTktQDjRc-cwXIITOZu6dnxHtrV5EUcoJOh3UTWcmEgsCKe1THZsJ2lZV1yibaX_GTC5QTmvSrQKwjkUWIrVJXy6xKfX8NslfnuG1ztIxYREZMwKtEadietMNK520m6Jzoj9MVVjjkuhsTj64qMselA2owYEvkazWdKcDE27oMmu0aQ3nkad99xDQQI_6_kUoa9-q7eOaGmeAqxCGvdZSCzBXZGV9zilGs71IZ40KWYEZlTD9pBTBvsey-JwdgKLBRRAJMoo20dHXDSw7kwN1fuk-wSYHNC37KfGBK_QCncekYewQGRoLK5qSSuGRgqV6CcObdRyhYZL9fX7mn19_Zo1UuqdFSMFJa_rzvXQOkEdzd13HQUcBEgPdRfjrqeUSr6b5SjFNJlMxqEtY5s-8KF5O8GpJyuDPFCxfl9EId3-oA0aEJMUz2b5MjhaoS4IgkXSWkKhMNG3sqz2NKewdyLJG1D-dIlnS956l62LRuP4bW8ZM_yaV7VwrT9GjxxnV9x7Q0L_wqm_r3nDSD_FQdCR1ey6H6z41j2Hh8ScGG3iUC9N6GTujjJXB3Vtb_S4Tn4YV6CNDh21Kerk46kf7-6U9d4TIxxKBtLUHIZ3k3LpHymH_ez3lPtrzdJJM_Ntwsp8J7rsrWTp_5Fs-48lu9zw9qOGl2d8Ub8ACbMhwuEGAAA=
This is the same example compiled with
vite build
:https://static.laszlokorte.de/svelte-debug/
Try to use the select box to first select component D, which does not export any functions, then switch back to component A. See the browser console to observe how the null value is logged last.
This is the exact project the example was built from.
https://github.com/laszlokorte/svelte5-debug-component-binding/blob/main/src/App.svelte#L39
Logs
No response
System Info
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: