@@ -71,6 +71,8 @@ export function EPUBProvider({ children }: { children: ReactNode }) {
7171 const tocRef = useRef < NavItem [ ] > ( [ ] ) ;
7272 const locationRef = useRef < string | number > ( currDocPage ) ;
7373 const isEPUBSetOnce = useRef ( false ) ;
74+ // Should pause ref
75+ const shouldPauseRef = useRef ( true ) ;
7476
7577 /**
7678 * Clears all current document state and stops any active TTS
@@ -80,6 +82,11 @@ export function EPUBProvider({ children }: { children: ReactNode }) {
8082 setCurrDocName ( undefined ) ;
8183 setCurrDocText ( undefined ) ;
8284 setCurrDocPages ( undefined ) ;
85+ isEPUBSetOnce . current = false ;
86+ bookRef . current = null ;
87+ renditionRef . current = undefined ;
88+ locationRef . current = 1 ;
89+ tocRef . current = [ ] ;
8390 stop ( ) ;
8491 } , [ setCurrDocPages , stop ] ) ;
8592
@@ -341,10 +348,12 @@ export function EPUBProvider({ children }: { children: ReactNode }) {
341348
342349 // Handle special 'next' and 'prev' cases
343350 if ( location === 'next' && renditionRef . current ) {
351+ shouldPauseRef . current = false ;
344352 renditionRef . current . next ( ) ;
345353 return ;
346354 }
347355 if ( location === 'prev' && renditionRef . current ) {
356+ shouldPauseRef . current = false ;
348357 renditionRef . current . prev ( ) ;
349358 return ;
350359 }
@@ -359,7 +368,8 @@ export function EPUBProvider({ children }: { children: ReactNode }) {
359368
360369 locationRef . current = location ;
361370 if ( bookRef . current && renditionRef . current ) {
362- extractPageText ( bookRef . current , renditionRef . current ) ;
371+ extractPageText ( bookRef . current , renditionRef . current , shouldPauseRef . current ) ;
372+ shouldPauseRef . current = true ;
363373 }
364374 } , [ id , skipToLocation , extractPageText , setIsEPUB ] ) ;
365375
0 commit comments