diff --git a/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js b/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js index ac6eda8c618a..eb62eb5a7352 100644 --- a/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js +++ b/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js @@ -23,6 +23,7 @@ import {ScrollView, View} from 'react-native'; import setUpIntersectionObserver from 'react-native/src/private/setup/setUpIntersectionObserver'; import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement'; import DOMRectReadOnly from 'react-native/src/private/webapis/geometry/DOMRectReadOnly'; +import * as IntersectionObserverManager from 'react-native/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager'; declare const IntersectionObserver: Class; declare const IntersectionObserverEntry: Class; @@ -4275,6 +4276,45 @@ describe('IntersectionObserver', () => { }); }); }); + + it('should dispatch other observers after ignoring disconnected entries', () => { + const root = Fantom.createRoot(); + const firstNodeRef = createRef(); + const secondNodeRef = createRef(); + + Fantom.runTask(() => { + root.render( + <> + + + , + ); + }); + + const firstNode = ensureReactNativeElement(firstNodeRef.current); + const secondNode = ensureReactNativeElement(secondNodeRef.current); + const firstCallback = jest.fn(); + const secondCallback = jest.fn(); + let firstObserver: IntersectionObserver; + + Fantom.runTask(() => { + firstObserver = new IntersectionObserver(firstCallback); + observer = new IntersectionObserver(secondCallback); + firstObserver.observe(firstNode); + observer.observe(secondNode); + + Fantom.scheduleTask(() => { + const firstObserverId = firstObserver.__getObserverID(); + if (firstObserverId == null) { + throw new Error('Expected the first observer to be registered'); + } + IntersectionObserverManager.unregisterObserver(firstObserverId); + }); + }); + + expect(firstCallback).not.toHaveBeenCalled(); + expect(secondCallback).toHaveBeenCalledTimes(1); + }); }); describe('IntersectionObserverEntry global constructor', () => { diff --git a/packages/react-native/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js b/packages/react-native/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js index 97e0fcf49051..72d167067757 100644 --- a/packages/react-native/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js +++ b/packages/react-native/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js @@ -266,7 +266,7 @@ function doNotifyIntersectionObservers(): void { if (!registeredObserver) { // This could happen if the observer is disconnected between commit // and mount. In this case, we can just ignore the entries. - return; + continue; } const {observer, callback} = registeredObserver;