diff --git a/shared/editor/components/Frame.tsx b/shared/editor/components/Frame.tsx index 4736244a94..85ed269f71 100644 --- a/shared/editor/components/Frame.tsx +++ b/shared/editor/components/Frame.tsx @@ -1,8 +1,7 @@ -import { observable } from "mobx"; -import { observer } from "mobx-react"; -import { OpenIcon } from "outline-icons"; import * as React from "react"; +import { useState, useEffect, useRef } from "react"; import styled from "styled-components"; +import { OpenIcon } from "outline-icons"; import { Optional } from "utility-types"; import { s } from "../../styles"; import { sanitizeUrl } from "../../utils/urls"; @@ -30,84 +29,82 @@ type PropsWithRef = Props & { forwardedRef: React.Ref; }; -@observer -class Frame extends React.Component { - mounted: boolean; +function Frame({ + border, + style = {}, + forwardedRef, + icon, + title, + canonicalUrl, + isSelected, + referrerPolicy, + className = "", + src, + ...rest +}: PropsWithRef) { + const [isLoaded, setIsLoaded] = useState(false); + const mountedRef = useRef(true); - @observable - isLoaded = false; + useEffect(() => { + // Set mounted flag + mountedRef.current = true; + + // Load iframe after a small delay + const timer = setTimeout(() => { + if (mountedRef.current) { + setIsLoaded(true); + } + }, 0); - componentDidMount() { - this.mounted = true; - setTimeout(this.loadIframe, 0); - } + // Cleanup function + return () => { + mountedRef.current = false; + clearTimeout(timer); + }; + }, []); - componentWillUnmount() { - this.mounted = false; - } + const showBottomBar = !!(icon || canonicalUrl); - loadIframe = () => { - if (!this.mounted) { - return; - } - this.isLoaded = true; - }; - - render() { - const { - border, - style = {}, - forwardedRef, - icon, - title, - canonicalUrl, - isSelected, - referrerPolicy, - className = "", - src, - } = this.props; - const showBottomBar = !!(icon || canonicalUrl); - - return ( - - {this.isLoaded && ( -