mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 08:21:39 -06:00
fix(reader): load correct chapter in web reader
Navigation sometimes treated stale rendered contents as successful navigation or failed silently when a section did not load properly. Ensure the target index matches the rendered content and throw on section load failure to prevent incorrect chapter display. Closes #203
This commit is contained in:
@@ -1010,11 +1010,14 @@ export class Paginator extends HTMLElement {
|
||||
}
|
||||
await this.#display(
|
||||
Promise.resolve(this.sections[index].load())
|
||||
.then((src) => ({ index, src, anchor, onLoad, select }))
|
||||
.then((src) => {
|
||||
if (!src) throw new Error(`Failed to load section ${index}`)
|
||||
return { index, src, anchor, onLoad, select }
|
||||
})
|
||||
.catch((e) => {
|
||||
console.warn(e)
|
||||
console.warn(new Error(`Failed to load section ${index}`))
|
||||
return {}
|
||||
throw e
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -133,7 +133,8 @@ export const makeBook = async (file) => {
|
||||
book = await new EPUB(loader).init()
|
||||
}
|
||||
} else if (await isPDF(file)) {
|
||||
const { makePDF } = await import('./pdf.js')
|
||||
const pdfModule = './pdf.js'
|
||||
const { makePDF } = await import(pdfModule)
|
||||
book = await makePDF(file)
|
||||
} else {
|
||||
const { isMOBI, MOBI } = await import('./mobi.js')
|
||||
@@ -536,11 +537,16 @@ export class View extends HTMLElement {
|
||||
|
||||
async goTo(target) {
|
||||
const resolved = this.resolveNavigation(target)
|
||||
const hasContent = () => (this.renderer.getContents?.()?.length ?? 0) > 0
|
||||
const hasContentFor = (nextResolved) => {
|
||||
const contents = this.renderer.getContents?.() ?? []
|
||||
if (!contents.length) return false
|
||||
if (typeof nextResolved?.index !== 'number') return true
|
||||
return contents.some((content) => content?.index === nextResolved.index)
|
||||
}
|
||||
const tryGoTo = async (nextResolved) => {
|
||||
try {
|
||||
await this.renderer.goTo(nextResolved)
|
||||
return hasContent()
|
||||
return hasContentFor(nextResolved)
|
||||
} catch (e) {
|
||||
console.warn(e)
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user