From e8b84f1a8f4ce6d6fbaf3a16f4e98b9ea573f85f Mon Sep 17 00:00:00 2001 From: jianghaotian3 Date: Fri, 28 Mar 2025 18:25:51 +0800 Subject: [PATCH] Fix target loss in shadow DOM by storing the target element --- src/index.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 2782fbb..6a6edcb 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -50,6 +50,9 @@ export default class InfiniteScroll extends Component { this.onEnd = this.onEnd.bind(this); } + // Fix target loss in shadow DOM by storing the target element + private _target: HTMLElement | undefined; + private throttledOnScrollListener: (e: MouseEvent) => void; private _scrollableNode: HTMLElement | undefined | null; private el: HTMLElement | undefined | Window & typeof globalThis; @@ -304,14 +307,16 @@ export default class InfiniteScroll extends Component { const target = this.props.height || this._scrollableNode - ? (event.target as HTMLElement) + ? (event.target as HTMLElement) || this._target : document.documentElement.scrollTop ? document.documentElement : document.body; // return immediately if the action has already been triggered, // prevents multiple triggers. - if (this.actionTriggered) return; + if (this.actionTriggered || !target) return; + + this._target = target; const atBottom = this.props.inverse ? this.isElementAtTop(target, this.props.scrollThreshold)