The current LottiePlayer.svelte component uses bind:clientWidth and bind:clientHeight on lines 560-561.
In svelte, bind:clientWidth/Height attaches an empty iframe to monitor these properties of an element. However, attaching an empty iframe can cause significant slowdowns.
This use case of bind:clientWidth/Height isn't even justified, because the ONLY time where these variables are used is in the toggleZoom() function, which just reads them. There's no effects that could run when these properties change, it's unnecessarily slowing down the web page. Plus, we already have a wrapperRef which references the exact element these bindings are on.
Solution:
Get rid of the old variables.
Get rid the lines 560-561.
On the lines 485-486, use wrapperRef.clientHeight/Width.
--- wrapperRef.style.height = playerHeight + "px";
--- wrapperRef.style.width = playerWidth + "px";
+++ wrapperRef.style.height = wrapperRef.clientHeight + "px";
+++ wrapperRef.style.width = wrapperRef.clientWidth + "px";
Though I don't have the exact numbers, this will definitely speed up the component.
I'll create a pull request a little bit later.
The current
LottiePlayer.sveltecomponent usesbind:clientWidthandbind:clientHeighton lines 560-561.In svelte,
bind:clientWidth/Heightattaches an empty iframe to monitor these properties of an element. However, attaching an empty iframe can cause significant slowdowns.This use case of
bind:clientWidth/Heightisn't even justified, because the ONLY time where these variables are used is in thetoggleZoom()function, which just reads them. There's no effects that could run when these properties change, it's unnecessarily slowing down the web page. Plus, we already have awrapperRefwhich references the exact element these bindings are on.Solution:
Get rid of the old variables.
Get rid the lines 560-561.
On the lines 485-486, use
wrapperRef.clientHeight/Width.Though I don't have the exact numbers, this will definitely speed up the component.
I'll create a pull request a little bit later.