Skip to content

Commit 30036e9

Browse files
authored
tooltip: prevent crashing when using SSR (#742)
1 parent c523472 commit 30036e9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/tooltip/src/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,9 @@ function useTooltip<ElementType extends HTMLElement>({
296296
ourHandler: (event: EventType) => any
297297
) {
298298
// Use internal MouseEvent handler only if PointerEvent is not supported
299-
if ("PointerEvent" in window) return theirHandler;
299+
if (typeof window !== "undefined" && "PointerEvent" in window) {
300+
return theirHandler;
301+
}
300302

301303
return wrapEvent(theirHandler, ourHandler);
302304
}
@@ -666,7 +668,11 @@ function useDisabledTriggerOnSafari({
666668
ref: React.RefObject<HTMLElement>;
667669
}) {
668670
React.useEffect(() => {
669-
if (!("PointerEvent" in window) || !disabled || !isVisible) {
671+
if (
672+
!(typeof window !== "undefined" && "PointerEvent" in window) ||
673+
!disabled ||
674+
!isVisible
675+
) {
670676
return;
671677
}
672678

0 commit comments

Comments
 (0)