Description
Describe the bug
When using bind:this
on an image element, there's no way to use Svelte's native reactivity for that element.
Neither $derived
, $derived.by
or $effect
does work.
Only option is to use a workaround techniques, like using the onload
event listener.
Expected behavior
Once the image loads, trigger Svelte reactivity.
Edit:
After playing some more with this, bind:contentRect
also isn't reactive as it should be. When I start scaling an element (for example the said image), the bound state value of this element doesn't change. I again have to track the change based on something else, for example the function that scaled the image, and get the getBoundingClientRect()
value manually.
Also, documentation still shows the legacy mode example:
https://svelte.dev/docs/svelte/bind#bind:this
Instead of let canvas = $state();
it uses let canvas;
.
Reproduction
Playground link (Important: make sure you have cache disabled)
System Info
Windows 10, Chrome
Severity
annoyance