Skip to content

Commit d9293e2

Browse files
committed
🐛 Fix double epub.js render
This seemed to do the trick for me locally, at least. This component has a lot of code smells though, it's been a good minute since it was written and could use a more thorough change. Fixes #726
1 parent b4a8221 commit d9293e2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/browser/src/components/readers/epub/EpubJsReader.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import EpubReaderContainer from './EpubReaderContainer'
2525
import { applyTheme, stumpDark } from './themes'
2626

2727
// TODO: Fix all lifecycle lints
28+
// TODO: Consider a total re-write or at least thorough review of this component, it was written a while
29+
// ago and I feel like it could be improved
2830
// TODO: Support elapsed time tracking!!!!
2931

3032
// NOTE: http://epubjs.org/documentation/0.3/ for epubjs documentation overview
@@ -269,6 +271,7 @@ export default function EpubJsReader({ id, isIncognito }: EpubJsReaderProps) {
269271
[theme],
270272
)
271273

274+
const didRenderToScreen = useRef(false)
272275
/**
273276
* This effect is responsible for rendering the epub to the screen. It will only run once
274277
* when the book is has been loaded. It will also set the initial location and theme
@@ -278,7 +281,8 @@ export default function EpubJsReader({ id, isIncognito }: EpubJsReaderProps) {
278281
if (!book || !ref.current) return
279282

280283
book.ready.then(() => {
281-
if (book.spine) {
284+
if (book.spine && !didRenderToScreen.current) {
285+
didRenderToScreen.current = true
282286
const defaultLoc = book.rendition?.location?.start?.cfi
283287

284288
const boundingClient = ref.current?.getBoundingClientRect()

0 commit comments

Comments
 (0)