Skip to content

Commit 2df30fa

Browse files
committed
fix(ui): block content redraw when staring an article
1 parent a0280bb commit 2df30fa

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ui/src/articles/components/ArticleContent.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
22
import mousetrap from 'mousetrap'
3-
import React, { useContext, useEffect, useRef } from 'react'
3+
import React, { useContext, useEffect, useRef, useState } from 'react'
44

55
import { LocalConfigurationContext } from '../../context/LocalConfigurationContext'
66
import { Article } from '../models'
@@ -33,6 +33,7 @@ window.onload = function() {
3333
`
3434

3535
export 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

Comments
 (0)