refactor(frontend): resolve linting errors, and EPUB reader lifecycle errors (#2127)
* refactor(types): improve type safety by replacing 'any' with specific types in various components Signed-off-by: Balázs Szücs <bszucs1209@gmail.com> * fix(filters): handle undefined values in filter streams and update type for selected filters Signed-off-by: Balázs Szücs <bszucs1209@gmail.com> * refactor(epub-reader): improve rendition cleanup and enhance debug logging in helper functions Signed-off-by: Balázs Szücs <bszucs1209@gmail.com> * fix(epub-reader): handle errors during rendition and book destruction in ngOnDestroy Signed-off-by: Balázs Szücs <bszucs1209@gmail.com> --------- Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
@@ -257,6 +257,11 @@ export class EpubReaderComponent implements OnInit, OnDestroy {
|
||||
const cfi = this.rendition.currentLocation()?.start?.cfi;
|
||||
const locations = this.book.locations.save();
|
||||
|
||||
if (this.rendition) {
|
||||
this.rendition.destroy();
|
||||
this.rendition = null;
|
||||
}
|
||||
|
||||
this.initBook(locations);
|
||||
this.initRendition(cfi);
|
||||
this.updateViewerSetting();
|
||||
@@ -268,6 +273,11 @@ export class EpubReaderComponent implements OnInit, OnDestroy {
|
||||
const cfi = this.rendition.currentLocation()?.start?.cfi;
|
||||
const locations = this.book.locations.save();
|
||||
|
||||
if (this.rendition) {
|
||||
this.rendition.destroy();
|
||||
this.rendition = null;
|
||||
}
|
||||
|
||||
this.initBook(locations);
|
||||
this.initRendition(cfi);
|
||||
this.updateViewerSetting();
|
||||
@@ -829,7 +839,23 @@ export class EpubReaderComponent implements OnInit, OnDestroy {
|
||||
|
||||
if (this.rendition) {
|
||||
this.rendition.off('keyup', this.keyListener);
|
||||
try {
|
||||
this.rendition.destroy();
|
||||
} catch (e) {
|
||||
console.warn('Error destroying rendition in ngOnDestroy', e);
|
||||
}
|
||||
this.rendition = null;
|
||||
}
|
||||
|
||||
if (this.book) {
|
||||
try {
|
||||
this.book.destroy();
|
||||
} catch (e) {
|
||||
console.warn('Error destroying book in ngOnDestroy', e);
|
||||
}
|
||||
this.book = null;
|
||||
}
|
||||
|
||||
document.removeEventListener('keyup', this.keyListener);
|
||||
|
||||
if (this.hideControlsTimeout) {
|
||||
|
||||
@@ -15,13 +15,13 @@ export function getCfiFromHref(book: Book, href: string): string | null {
|
||||
const section = book.spine.get(href);
|
||||
|
||||
if (!section || !section.document) {
|
||||
console.warn('Section or section.document is undefined for href:', href);
|
||||
console.debug('Section or section.document is undefined for href:', href);
|
||||
return null;
|
||||
}
|
||||
|
||||
const el = id ? section.document.getElementById(id) : section.document.body;
|
||||
if (!el) {
|
||||
console.warn('Element not found in section.document for href:', href);
|
||||
console.debug('Element not found in section.document for href:', href);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user