Skip to content

Commit 35309e0

Browse files
committed
fix(modal): fix modal SSR
1 parent 4c4f401 commit 35309e0

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/components/Dialog/Modal.web.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ class Modal extends React.PureComponent<ModalProps> {
2828
document.body.style.position = 'relative';
2929
document.body.style.height = 'initial';
3030
document.body.style.minHeight = 'initial';
31+
3132
this.modalRoot.appendChild(this.el);
3233
}
3334

35+
public componentDidUpdate() {
36+
const { visible, isScrollable = false } = this.props;
37+
if (visible && !isScrollable) document.body.style.overflow = 'hidden';
38+
else document.body.style.overflow = '';
39+
}
40+
3441
public componentWillUnmount() {
3542
this.modalRoot.removeChild(this.el);
3643
}
@@ -47,10 +54,6 @@ class Modal extends React.PureComponent<ModalProps> {
4754
public render() {
4855
const { transparent, visible, isScrollable = false } = this.props;
4956

50-
// Prevent body scroll
51-
if (visible && !isScrollable) document.body.style.overflow = 'hidden';
52-
// Reset to normal
53-
if (!visible) document.body.style.overflow = '';
5457
if (!visible) return null;
5558

5659
return ReactDOM.createPortal(

0 commit comments

Comments
 (0)