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

Useless bind:clientWidth and bind:clientHeight #19

Open
kaizjen opened this issue Sep 24, 2023 · 0 comments
Open

Useless bind:clientWidth and bind:clientHeight #19

kaizjen opened this issue Sep 24, 2023 · 0 comments

Comments

@kaizjen
Copy link

kaizjen commented Sep 24, 2023

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.

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