Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<IntersectionObserverType>;
declare const IntersectionObserverEntry: Class<IntersectionObserverEntryType>;
Expand Down Expand Up @@ -4275,6 +4276,45 @@ describe('IntersectionObserver', () => {
});
});
});

it('should dispatch other observers after ignoring disconnected entries', () => {
const root = Fantom.createRoot();
const firstNodeRef = createRef<HostInstance>();
const secondNodeRef = createRef<HostInstance>();

Fantom.runTask(() => {
root.render(
<>
<View ref={firstNodeRef} />
<View ref={secondNodeRef} />
</>,
);
});

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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading