Skip to content

Commit 9ed1340

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 9ed1340

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 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()
@@ -703,6 +707,12 @@ export default function EpubJsReader({ id, isIncognito }: EpubJsReaderProps) {
703707
// 'epubcfi(/6/12!/4[3Q280-a9efbf2f573d4345819e3829f80e5dbc]/2[prologue]/4[prologue-text]/8/1:56)',
704708
// ).then((res) => console.log('cfiWithinAnother', res))
705709

710+
console.log('EpubJsReader', {
711+
ebook,
712+
book,
713+
currentLocation,
714+
})
715+
706716
if (!ebook || !ebook.media) {
707717
return null
708718
}

0 commit comments

Comments
 (0)