Skip to content

Useless bind:clientWidth and bind:clientHeight #19

Description

@whzard

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions