Skip to content

Commit

Permalink
Improve intersection observer errors when trying to observe nullish t…
Browse files Browse the repository at this point in the history
…argets

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
  • Loading branch information
rubennorte authored and facebook-github-bot committed Oct 29, 2024
1 parent 9792d5e commit 4442947
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'.",
Expand Down

0 comments on commit 4442947

Please sign in to comment.