Skip to content

[Bug] view.goTo(index) 因 decodeURIComponent 静默失败,按索引跳章不生效(TTS 章节切换 / AI 引用跳转) #747

Description

@chy5301

Type

Bug

Description

packages/foliate-js/view.js:515 无条件对 target 做 decode:

async goTo(target) {
    target = decodeURIComponent(target)   // ← 数字/对象在这里被转成字符串
    const resolved = this.resolveNavigation(target)

而 resolveNavigation(view.js:500-508)的第一个分支是 typeof target === "number" —— decode 之后这个判断永远为 false。

实测(Node):

decodeURIComponent(5)          // → "5"(string)
decodeURIComponent({index:5})  // → "[object Object]"

后续链路:CFI.isCFI.test("5") 为 false → book.resolveHref("5") 找不到 → 返回 null → renderer.goTo(null) → paginator.js:3003 读 resolved.index 抛 TypeError → 被 view.js:521 的 try/catch 吞掉,只在 console 打一行 Could not go to 5。

用户侧表现是「点了没反应,也没有任何报错」。

受影响的调用点

  • 桌面端 FoliateViewer.goToIndex(FoliateViewer.tsx:1549):viewRef.current?.goTo(index) 直接传数字
  • 移动端 window.goToSection(reader.template.html:4111-4122):传 {index} 对象
  • 经由上述两处:桌面 TTS 章节切换、AI 引用跳转(ReaderView.tsx:663/671/1030/2778),移动 TTS 上/下一章(useReaderTTS.ts:1980/2002/2500)

建议修复

view.js:515 改成只对字符串解码:

if (typeof target === 'string') target = decodeURIComponent(target)

或在封装层绕开 view.goTo,直接调 view.renderer.goTo({ index })。改后需 pnpm run build:reader 让移动端生效。

补充:paginator.js:3084 的 prevSection() / nextSection() 调的是 Paginator 自己的 goTo,不经过 view.js,因此不受此 bug 影响。

说明

本条来自代码路径静态分析 + Node 中对 decodeURIComponent 行为的实测,未做运行时验证。建议维护者实机确认一次:桌面端开 devtools 点 TTS 章节切换,看 console 有无 Could not go to <数字>。若实际能跳转,说明存在我没找到的 target 归一化路径,本 issue 可关闭。

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions