diff --git a/app/embeds/Gist.js b/app/embeds/Gist.js index 177c4eecc..c777051e3 100644 --- a/app/embeds/Gist.js +++ b/app/embeds/Gist.js @@ -15,13 +15,23 @@ type Props = {| class Gist extends React.Component { static ENABLED = [URL_REGEX]; + ref = React.createRef(); get id() { const gistUrl = new URL(this.props.attrs.href); return gistUrl.pathname.split("/")[2]; } - updateIframeContent = (iframe: ?HTMLIFrameElement) => { + componentDidMount() { + this.updateIframeContent(); + } + + componentDidUpdate() { + this.updateIframeContent(); + } + + updateIframeContent = () => { + const iframe = this.ref.current; if (!iframe) return; const id = this.id; @@ -39,6 +49,8 @@ class Gist extends React.Component { ""; const iframeHtml = `${styles}${gistScript}`; + if (!doc) return; + doc.open(); doc.writeln(iframeHtml); doc.close(); @@ -50,13 +62,14 @@ class Gist extends React.Component { return (