From 48f750f8968ca206bdcc7a29b61c43e093a1de78 Mon Sep 17 00:00:00 2001 From: Pavel Mineev Date: Wed, 9 Jun 2021 21:02:38 +0300 Subject: [PATCH] chage iframe size if any element is changed --- frontend/app/components/root/root.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/frontend/app/components/root/root.tsx b/frontend/app/components/root/root.tsx index d2c9dbed51..1a017fdb71 100644 --- a/frontend/app/components/root/root.tsx +++ b/frontend/app/components/root/root.tsx @@ -1,4 +1,5 @@ import { h, Component, FunctionComponent, Fragment } from 'preact'; +import { useEffect, useRef } from 'preact/hooks'; import { useSelector } from 'react-redux'; import b from 'bem-react-helper'; import { IntlShape, useIntl, FormattedMessage, defineMessages } from 'react-intl'; @@ -118,7 +119,7 @@ export class Root extends Component { isSettingsVisible: false, }; - componentWillMount() { + componentDidMount() { const userloading = this.props.fetchUser().finally(() => this.setState({ isUserLoading: false })); Promise.all([userloading, this.props.fetchComments()]).finally(() => { @@ -334,9 +335,21 @@ export const ConnectedRoot: FunctionComponent = () => { const props = useSelector(mapStateToProps); const actions = useActions(boundActions); const intl = useIntl(); + const rootRef = useRef(null); + + useEffect(() => { + // TODO: throttle updates + const observer = new MutationObserver(() => { + postMessageToParent({ height: document.body.offsetHeight }); + }); + + observer.observe(rootRef.current, { attributes: true, childList: true, subtree: true }); + + return () => observer.disconnect(); + }, []); return ( -
+