diff --git a/pkg/interface/src/views/components/VirtualScroller.tsx b/pkg/interface/src/views/components/VirtualScroller.tsx index 70f6dd8897..c7a3361ee0 100644 --- a/pkg/interface/src/views/components/VirtualScroller.tsx +++ b/pkg/interface/src/views/components/VirtualScroller.tsx @@ -115,6 +115,10 @@ export default class VirtualScroller extends Component(); + /** + * A set of child refs which have been unmounted + */ + private orphans = new Set(); /** * If saving, the bottommost visible element that we pin our scroll to */ @@ -140,6 +144,10 @@ export default class VirtualScroller extends Component) { super(props); this.state = { @@ -157,6 +165,7 @@ export default class VirtualScroller extends Component extends Component { + log('scroll', 'initialised scroll'); + this.restore(); + this.initScroll = null; + }, 100); } + + + cleanupRefs = () => { + if(this.saveDepth > 0) { + return; + } + [...this.orphans].forEach(o => { + const index = bigInt(o); + this.childRefs.delete(index); + }); + this.orphans.clear(); + }; + // manipulate scrollbar manually, to dodge change detection updateScroll = IS_IOS ? () => {} : _.throttle(() => { if(!this.window || !this.scrollRef) { @@ -199,6 +227,12 @@ export default class VirtualScroller extends Component extends Component { requestAnimationFrame(() => { this.restore(); - requestAnimationFrame(() => { - - }); }); }); } @@ -339,6 +370,10 @@ export default class VirtualScroller extends Component 0) { log('bail', 'deep scroll queue'); return; @@ -394,8 +429,15 @@ export default class VirtualScroller extends Component extends Component extends Component { if(element) { this.childRefs.set(index, element); + this.orphans.delete(index.toString()); } else { - setTimeout(() => { - this.childRefs.delete(index); - }); + this.orphans.add(index.toString()); } }