-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
bind:this
on <img>
element doesn't trigger reactivity
#15806
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
Comments
The For the |
@dummdidumm Is there any reason why you wouldn't want |
It would be inconsistent, |
Here's the example for |
It works correctly according to the ResizeObserver specs.
|
Ok guys, in all honesty, should I just use pure JavaScript then? What's the purpose of |
The problem is that
|
Hmm, I see. Thanks for explanation. I was however surprised by the behavior of |
Closing since this works as designed, even if unfortunate in the case of |
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 thegetBoundingClientRect()
value manually.Also, documentation still shows the legacy mode example:
https://svelte.dev/docs/svelte/bind#bind:this
Instead of
let canvas = $state();
it useslet canvas;
.Reproduction
Playground link (Important: make sure you have cache disabled)
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: