From 0ff2956c5881fc58432772c0eb8d9271da783bf1 Mon Sep 17 00:00:00 2001 From: netsgnut <284779+netsgnut@users.noreply.github.com> Date: Fri, 26 Feb 2021 20:42:08 +0800 Subject: [PATCH] Added guard against HTMLElement in callSubscriber --- CHANGELOG.md | 6 ++++++ src/index.ts | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f2b9ca..06c7913 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# Unreleased + +### Misc + +- Added guard against undefined `HTMLElement` in `callSubscriber` for SSR + # [7.0.0](https://github.com/ZeeCoder/use-resize-observer/compare/v6.1.0...v7.0.0) (2020-11-11) ### Bug Fixes diff --git a/src/index.ts b/src/index.ts index e5a365a..7f37779 100644 --- a/src/index.ts +++ b/src/index.ts @@ -38,7 +38,7 @@ function useResolvedElement( element = callbackRefElement.current; } else if (refElement.current) { element = refElement.current; - } else if (refOrElement instanceof HTMLElement) { + } else if (typeof HTMLElement !== "undefined" && refOrElement instanceof HTMLElement) { element = refOrElement; } @@ -59,7 +59,7 @@ function useResolvedElement( } }; - if (refOrElement && !(refOrElement instanceof HTMLElement)) { + if (refOrElement && typeof HTMLElement !== "undefined" && !(refOrElement instanceof HTMLElement)) { // Overriding the default ref with the given one ref = refOrElement; }