Kaynağa Gözat

fixed issue when target elements are not observed anymore

Former-commit-id: a12466bb051f8d9deea5a362af6a9ee43f47be7b
Gildas 6 yıl önce
ebeveyn
işleme
771d5435b3
1 değiştirilmiş dosya ile 11 ekleme ve 8 silme
  1. 11 8
      lib/hooks/content/content-hooks-frames-web.js

+ 11 - 8
lib/hooks/content/content-hooks-frames-web.js

@@ -128,14 +128,17 @@
 		const docBoundingRect = scrollingElement.getBoundingClientRect();
 		Array.from(observers, ([intersectionObserver, observer]) => {
 			const rootBoundingRect = observer.options && observer.options.root && observer.options.root.getBoundingClientRect();
-			observer.callback(observedElements.get(intersectionObserver).map(target => {
-				const boundingClientRect = target.getBoundingClientRect();
-				const isIntersecting = true;
-				const intersectionRatio = 1;
-				const rootBounds = observer.options && observer.options.root ? rootBoundingRect : docBoundingRect;
-				const time = 0;
-				return { target, intersectionRatio, boundingClientRect, intersectionRect: boundingClientRect, isIntersecting, rootBounds, time };
-			}), intersectionObserver);
+			const targetElements = observedElements.get(intersectionObserver);
+			if (targetElements) {
+				observer.callback(targetElements.map(target => {
+					const boundingClientRect = target.getBoundingClientRect();
+					const isIntersecting = true;
+					const intersectionRatio = 1;
+					const rootBounds = observer.options && observer.options.root ? rootBoundingRect : docBoundingRect;
+					const time = 0;
+					return { target, intersectionRatio, boundingClientRect, intersectionRect: boundingClientRect, isIntersecting, rootBounds, time };
+				}), intersectionObserver);
+			}
 		});
 		if (pendingRequestAnimationFrameCalls.size) {
 			Array.from(pendingRequestAnimationFrameCalls).forEach(([id, callback]) => {