From b93002ad93fb2f78ecab2092215a5c4a5d6f049b Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 16 Mar 2021 22:53:32 -0700 Subject: [PATCH] fix: JS error when pasting gist link, closes #1963 --- app/embeds/Gist.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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 (