Skip to content

Commit

Permalink
fix(react/portal): fix portal error when in SSR mode
Browse files Browse the repository at this point in the history
  • Loading branch information
travor20814 committed Dec 7, 2023
1 parent 85b1778 commit dddfa3a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/react/src/Portal/Portal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react/jsx-no-useless-fragment */
import {
FC,
ReactNode,
Expand Down Expand Up @@ -34,7 +35,7 @@ const Portal: FC<PortalProps> = (props) => {
const [portalElement, setPortalElement] = useState(() => (
disablePortal
? null
: getElement(container) || document.body
: getElement(container)
));

useEffect(() => {
Expand All @@ -43,6 +44,9 @@ const Portal: FC<PortalProps> = (props) => {
}
}, [container, disablePortal]);

/** This element is fully client side, so `return null` on server side */
if (typeof window === 'undefined') return null;

if (disablePortal || !portalElement) {
return <>{children}</>;
}
Expand Down

0 comments on commit dddfa3a

Please sign in to comment.