diff --git a/frontend/app/components/root/root.tsx b/frontend/app/components/root/root.tsx index d2c9dbed..1a017fdb 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 ( -
+