Skip to content

[labs/virtualizer] DOM update doesn't successfully complete under some circumstances #3243

@monkeyjabs

Description

@monkeyjabs

Which package(s) are affected?

Virtualizer (@lit-labs/virtualizer)

Description

We have a scenario in our app where the LitVirtualizer doesn't render horizontal flow correctly on the first load in the Safari browser. A subsequent update to the items list seems to fix the issue.

  • This only reproduces within our app and Safari
  • I'm unable to reproduce this when isolating this into its own sandbox

Our code specified this:

<x-virtualizer
    style="min-height: 50px"
    .layout=${flow({ direction: "horizontal" })}
    scroller
    .items=${this.items}
    .renderItem=${this._renderItemProxy}
></x-virtualizer>

When inspecting the DOM on Safari during the first load I noticed the elements inside the LitVirtualizer did not the transform style it needs to layout out the horizontally:

<x-virtualizer style="min-height: 50px; display: block; position: relative; contain: strict; overflow: auto;" scroller="" dir="ltr">
<div virtualizer-sizer="" style="position: absolute; margin: -2px 0px 0px; padding: 0px; visibility: hidden; font-size: 2px; transform: translate(1000px, 0px);">&nbsp;</div>
            <div class="proxy-item-ltr " id="idx-0">
            </div>
            <div class="proxy-item-ltr " id="idx-1">
            </div>
            <div class="proxy-item-ltr " id="idx-2">
            </div>     
</x-virtualizer> 

When it's working correctly we can see that in-style is applied to these items:

<x-virtualizer style="min-height: 50px; display: block; position: relative; contain: strict; overflow: auto;" scroller="" dir="ltr">
    <div class="proxy-item-ltr " id="idx-0" style="position: absolute; box-sizing: border-box; transform: translate(0px, 0px); left: 0px;">      
    </div>
    <div class="proxy-item-ltr " id="idx-1" style="position: absolute; box-sizing: border-box; transform: translate(216px, 0px); left: 0px;">     
    </div>
    <div class="proxy-item-ltr " id="idx-2" style="position: absolute; box-sizing: border-box; transform: translate(432px, 0px); left: 0px;            
    </div>
</x-virtualizer>

Reproduction

Initial of the our app (unfortunately can't share to public yet)

Workaround

In the component initialize the items array with an initial value and on firstUpdated() life cycle method update the items array again with a different sets of value

Is this a regression?

No or unsure. This never worked, or I haven't tried before.

Affected versions

"@lit-labs/virtualizer": "0.7.1"

Browser/OS/Node environment

Browser: Version 15.6 (17613.3.9.1.5)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions