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

lit-virtualizer repeated use with LitElement - adds scroll window event listener more than once #55

Open
cintaccs opened this issue Mar 7, 2020 · 2 comments
Labels

Comments

@cintaccs
Copy link

cintaccs commented Mar 7, 2020

In a LitElement component - render method:
render() { return html<lit-virtualizer .items=${items} .renderItem=${this.listitem}>; }
keeps adding:

Screenshot 2020-03-08 at 00 29 52

A potential solution - seems to work but a bit "hacky" - VirtualScroller.js set container(container) method:

            this._containerRO.disconnect();
            this._containerSize = null;
            if (oldEl) {
                if (this._containerInlineStyle) {
                    oldEl.setAttribute('style', this._containerInlineStyle);
                }
                else {
                    oldEl.removeAttribute('style');
                }
                this._containerInlineStyle = null;
                if (oldEl === this._scrollTarget) {
                    oldEl.removeEventListener('scroll', this, { passive: true });
                    this._sizer && this._sizer.remove();
                }
            }
            else {                
                if (!window.scrollLitVirtual) {
                    console.log('window.scrollLitVirtual  setting scroll on window once');
                    addEventListener('scroll', this, { passive: true });
                    window.scrollLitVirtual = true;
                }
                // First time container was setup, add listeners only now.
            }

if (!window.scrollLitVirtual) { is the condition added to avoid continous scroll event listeners to be added. I have tried several ways to capture the window.scroll event on DisconnectedCallBack on the Lit-Element etc. but maybe because of the "this" handler reference - it is impossible (for me at least) to figure out a way to get rid of the event listeners no longer relevant. For whatever reason the garbage collection is not picking these up. It might be related to the way I switch between lit-element controls ... but maybe it is an issue for others too. I have tried just using the scroll directive - but it is the same issue also using the directive.

Anyone with the same issue? or a better way to avoid the hack?

@cintaccs
Copy link
Author

Hi,
Are any updates planned to the lit-virtualizer in the short/medium term? eventually with a fix to above.

@graynorton
Copy link
Contributor

The code in this area has been significantly reworked, and I believe this issue should no longer occur. Please check against 0.7.0-pre.2 or later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants