From 4442947e729909895fb7e1395873b10daaef4452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Tue, 29 Oct 2024 09:42:32 -0700 Subject: [PATCH] Improve intersection observer errors when trying to observe nullish targets Summary: Changelog: [internal] Small devx improvement to distinguish problems caused by calling `IntersectionObserver.observe` with null or undefined, vs. other values not supported by the API (like legacy refs). Differential Revision: D65150750 --- .../webapis/intersectionobserver/IntersectionObserver.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/react-native/src/private/webapis/intersectionobserver/IntersectionObserver.js b/packages/react-native/src/private/webapis/intersectionobserver/IntersectionObserver.js index 1783adbc1674..4c3874adea37 100644 --- a/packages/react-native/src/private/webapis/intersectionobserver/IntersectionObserver.js +++ b/packages/react-native/src/private/webapis/intersectionobserver/IntersectionObserver.js @@ -131,6 +131,12 @@ export default class IntersectionObserver { * To stop observing the element, call `IntersectionObserver.unobserve()`. */ observe(target: ReactNativeElement): void { + if (target == null) { + throw new TypeError( + "Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is null or undefined.", + ); + } + if (!(target instanceof ReactNativeElement)) { throw new TypeError( "Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'ReactNativeElement'.",