From e0e1b09c7174cc8a78db812a5258b156b0a9dfff Mon Sep 17 00:00:00 2001 From: Tyler Jones Date: Tue, 5 May 2020 18:07:20 -0700 Subject: [PATCH] portal: fix TypeError when using hot-loader (#574) --- packages/portal/src/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/portal/src/index.tsx b/packages/portal/src/index.tsx index fe2decced..447b2163f 100644 --- a/packages/portal/src/index.tsx +++ b/packages/portal/src/index.tsx @@ -26,6 +26,8 @@ const Portal: React.FC = ({ children, type = "reach-portal" }) => { let [, forceUpdate] = useState(); useIsomorphicLayoutEffect(() => { + // This ref may be null when a hot-loader replaces components on the page + if (!mountNode.current) return; // It's possible that the content of the portal has, itself, been portaled. // In that case, it's important to append to the correct document element. const ownerDocument = mountNode.current!.ownerDocument;