From 07d488c826525ad6717f5b665160a30440328a42 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 9 Aug 2020 21:53:57 -0700 Subject: [PATCH] fix: GitHub Gist embed reliability, closes #1400 --- app/embeds/Gist.js | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/app/embeds/Gist.js b/app/embeds/Gist.js index 529a382ec..d70c00728 100644 --- a/app/embeds/Gist.js +++ b/app/embeds/Gist.js @@ -13,31 +13,16 @@ type Props = {| |}; class Gist extends React.Component { - iframeNode: ?HTMLIFrameElement; - static ENABLED = [URL_REGEX]; - componentDidMount() { - this.updateIframeContent(); - } - get id() { const gistUrl = new URL(this.props.attrs.href); return gistUrl.pathname.split("/")[2]; } - updateIframeContent() { - const id = this.id; - const iframe = this.iframeNode; + updateIframeContent = (iframe: ?HTMLIFrameElement) => { if (!iframe) return; - - // We need to add some temporary content to the iframe for the document - // to be available, otherwise it's undefined on first load - const temp = document.getElementById("gist"); - if (temp) { - temp.innerHTML = ""; - temp.appendChild(iframe); - } + const id = this.id; // $FlowFixMe let doc = iframe.document; @@ -56,16 +41,14 @@ class Gist extends React.Component { doc.open(); doc.writeln(iframeHtml); doc.close(); - } + }; render() { const id = this.id; return (