Skip to content

fix(h5): clear download timeout after completion - #19532

Merged
Single-Dancer merged 1 commit into
NervJS:mainfrom
Jarvis636431:fix/h5-download-timeout-cleanup
Oct 16, 2026
Merged

Single-Dancer merged 1 commit into
NervJS:mainfrom
Jarvis636431:fix/h5-download-timeout-cleanup

Conversation

@Jarvis636431

@Jarvis636431 Jarvis636431 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

这个 PR 做了什么?

Closes #19531

H5 downloadFile 在成功或网络错误后仍保留超时定时器,之后会再次触发 fail/complete。本 PR 在 xhr.onload 和 xhr.onerror 中清除该定时器。

新增 4 个回归用例,覆盖成功、网络错误、取消和超时,检查定时器清理及回调次数。修复前成功/错误 2 个用例失败,修复后 4 个全部通过。

这个 PR 是什么类型?

这个 PR 涉及以下平台:

  • Web 端(H5)

验证

  • pnpm --filter @tarojs/taro-h5 exec jest --watchman=false --runInBand __tests__/network/download.test.ts:4 个用例通过。
  • 修改文件 ESLint 通过。
  • 使用受控 XMLHttpRequest 和 fake timers 验证,未声明真实浏览器端到端验证结果。
  • 完整 H5 测试首次执行受缺失的工作区构建产物阻塞;正在补齐构建后复查。

Summary by CodeRabbit

  • Bug Fixes
    • 下载请求成功或发生网络错误时,会及时清除超时计时器。

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bc20e0f4-d090-46a9-b321-e8cd6604687a
📥 Commits

Reviewing files that changed from the base of the PR and between 42f568a and dd60f02.

📒 Files selected for processing: 2
  • packages/taro-h5/__tests__/network/download.test.ts
  • packages/taro-h5/src/api/network/download.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

downloadFile 在 XHR 成功加载或发生网络错误时清除超时计时器。新增测试覆盖成功、网络错误、主动中止和超时结果。

Changes

下载请求超时清理

Layer / File(s) Summary
清理超时计时器并验证生命周期
packages/taro-h5/src/api/network/download.ts, packages/taro-h5/__tests__/network/download.test.ts
成功加载和网络错误处理会清除超时计时器。测试验证四种终止结果的 Promise 错误信息、回调次数、计时器清理及 abort 调用。

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to dd60f

The H5 download timer is cleared after success or network error, preventing a stale timeout from causing duplicate callbacks. Controlled-XHR tests cover success, network error, caller abort, and timeout; no actionable merge risk is evident.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题准确概括了主要变更:在 H5 downloadFile 完成后清除下载超时计时器。标题简洁、明确,并与成功和网络错误场景的修复相关。
Linked Issues check Passed PR 满足直接关联 issue [#19531] 的编码要求。packages/taro-h5/src/api/network/download.ts 在 xhr.onload 和 xhr.onerror 中调用 clearTimeout(timeoutInter)。现有 xhr.onabort 也清理定时器,超时路径仍主动中止请求并报告一次失败。新增 `packages/ta…
Out of Scope Changes check Passed 变更范围与 issue [#19531] 一致。生产代码只修改 H5 downloadFile 的成功和网络错误清理逻辑。新增测试直接验证该修复及相关终止路径。未发现与该问题无关的功能、公共声明或平台变更。
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Full details: Linked Issues check

Explanation

PR 满足直接关联 issue [#19531] 的编码要求。packages/taro-h5/src/api/network/download.ts 在 xhr.onload 和 xhr.onerror 中调用 clearTimeout(timeoutInter)。现有 xhr.onabort 也清理定时器,超时路径仍主动中止请求并报告一次失败。新增 packages/taro-h5/__tests__/network/download.test.ts 覆盖成功、网络错误、取消和超时,并检查回调次数、定时器数量及 abort 调用次数。

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/taro-h5/__tests__/network/download.test.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

packages/taro-h5/src/api/network/download.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

我是小兔,蹦到下载旁,
成功落地,计时器收场。
网络出错,也能清理妥当,
中止与超时,各有回响。
四种结果,测试逐一照亮。

Comment @coderabbitai help to get the list of available commands.

@Single-Dancer Single-Dancer added this to the 4.3.1 milestone Oct 16, 2026
@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.58%. Comparing base (42f568a) to head (dd60f02).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #19532      +/-   ##
==========================================
+ Coverage   55.36%   55.58%   +0.22%     
==========================================
  Files         467      467              
  Lines       25652    25654       +2     
  Branches     6423     6390      -33     
==========================================
+ Hits        14201    14259      +58     
+ Misses       9493     9401      -92     
- Partials     1958     1994      +36     
Flag Coverage Δ
taro-cli 60.27% <ø> (ø)
taro-runtime 58.60% <ø> (ø)
taro-web 58.84% <100.00%> (+1.45%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/taro-h5/src/api/network/download.ts 93.84% <100.00%> (+87.49%) ⬆️

... and 15 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Single-Dancer
Single-Dancer merged commit 039023c into NervJS:main Oct 16, 2026
25 checks passed
@Jarvis636431
Jarvis636431 deleted the fix/h5-download-timeout-cleanup branch October 16, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[H5] downloadFile 成功或失败后仍触发超时回调

2 participants