11/* eslint-disable @typescript-eslint/no-var-requires */
22import mousetrap from 'mousetrap'
3- import React , { useContext , useEffect , useRef } from 'react'
3+ import React , { useContext , useEffect , useRef , useState } from 'react'
44
55import { LocalConfigurationContext } from '../../context/LocalConfigurationContext'
66import { Article } from '../models'
@@ -33,6 +33,7 @@ window.onload = function() {
3333`
3434
3535export default ( { article } : Props ) => {
36+ const [ alreadyRendered , setAlreadyRendered ] = useState ( false )
3637 const contentRef = useRef < HTMLDivElement > ( null )
3738 const { localConfiguration } = useContext ( LocalConfigurationContext )
3839 let { theme } = localConfiguration
@@ -42,8 +43,9 @@ export default ({ article }: Props) => {
4243 }
4344
4445 useEffect ( ( ) => {
45- if ( contentRef . current ) {
46+ if ( contentRef . current && ! alreadyRendered ) {
4647 const ifrm = document . createElement ( 'iframe' )
48+ console . log ( 'render' )
4749 contentRef . current . innerHTML = ''
4850 contentRef . current . appendChild ( ifrm )
4951 const doc = ifrm . contentWindow ? ifrm . contentWindow . document : ifrm . contentDocument
@@ -78,8 +80,9 @@ export default ({ article }: Props) => {
7880 doc . close ( )
7981 }
8082 ifrm . focus ( )
83+ setAlreadyRendered ( true )
8184 }
82- } , [ article , theme ] )
85+ } , [ alreadyRendered , article , theme ] )
8386
8487 return < article className = { styles . content } ref = { contentRef } />
8588}
0 commit comments