Repository navigation
fix(h5): 支持音频事件无参取消全部监听 - #19591
fix(h5): 支持音频事件无参取消全部监听#19591
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
| 层 / 文件 | 摘要 |
|---|---|
分离首次播放处理 packages/taro-h5/src/api/media/audio/InnerAudioContext.ts, packages/taro-h5/__tests__/media/audio-listeners.test.ts |
首次播放时设置 startTime 的处理改用独立的内部 play 监听器。测试验证移除 play 用户监听器后,首次播放和 seek 仍按预期设置时间,并覆盖上下文隔离。 |
管理事件注册与移除 packages/taro-h5/src/api/media/audio/InnerAudioContext.ts, packages/taro-h5/__tests__/media/audio-listeners.test.ts, packages/taro-h5/__tests__/media/audio.test.ts |
事件接口改用监听器管理方法。省略回调或传入 undefined 时移除该事件的全部用户监听器;传入回调时只移除匹配项。测试覆盖十种事件、重复移除、重新订阅及模拟对象的 removeEventListener。 |
销毁时清理监听器 packages/taro-h5/src/api/media/audio/InnerAudioContext.ts, packages/taro-h5/__tests__/media/audio-listeners.test.ts |
销毁时移除已管理的用户监听器和内部首次播放监听器。测试覆盖 DOM 回调参数与 this、重复注册、派发期间移除、销毁后不再触发回调及重复销毁。 |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related PRs
- NervJS/taro#19586:该 PR 修改
CallbackManager.trigger的派发期间移除行为;本 PR 的onStop和onError接口也使用该管理器。
Suggested reviewers: single-dancer
Merge Risk: 
Minimal · previous review 3c398
-
No actionable merge-blocking issue is established for the H5 audio listener changes. The change is ready for normal merge checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Title check
-
Explanation
标题“fix(h5): 支持音频事件无参取消全部监听”与变更内容一致。变更修改了 H5 端 InnerAudioContext 的监听器管理:省略 callback 时移除该事件的全部用户监听器,指定 callback 时只移除对应回调,并将首次播放的 startTime 内部监听器与用户 onPlay 监听器分离,销毁时同时解绑。标题准确概括了主要变更,且使用 fix(h5) 前缀说明作用范围。标题为中文,与仓库的提交规范一致。
Full details: Linked Issues check
-
Explanation
PR 满足直接关联 issue
#19590的编码要求。InnerAudioContext.ts为十个offXxx实现了两种行为:省略或传入undefined时移除该事件的全部用户监听,传入回调时仅移除该回调。offError和offStop将可选参数传给现有CallbackManager。独立的onFirstPlay监听器保留了首次播放的startTime处理,destroy同时移除用户监听器和内部监听器。新增测试覆盖十个事件、两种参数形式、重复移除、指定回调、隔离性、startTime和销毁清理。
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 3 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
小兔听见音符跳,play 监听各归其位。
移除回调清清楚,
销毁之后静悄悄。
耳边只剩月光摇。
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #19591 +/- ##
==========================================
+ Coverage 57.75% 57.83% +0.08%
==========================================
Files 470 470
Lines 25966 25987 +21
Branches 6511 6528 +17
==========================================
+ Hits 14996 15029 +33
- Misses 9038 9164 +126
+ Partials 1932 1794 -138
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Single-Dancer
left a comment
There was a problem hiding this comment.
审查提交:3c398a65e14b6cb0df36077f83f32fac62a26b8c。
未发现阻止合入的问题,建议合并。
核对了公开 createInnerAudioContext 入口、十类 on/off 监听、CallbackManager 无参清空路径,以及 destroy 和路由停止链路。原生 DOM 事件仍由 EventTarget 分发;用户监听登记与首次播放 startTime 监听分离,保留指定取消、去重、事件参数/this 和分发期间移除行为。
独立验证(固定 PR 快照,复用本地已有依赖,临时调整 Jest 模块映射及 Babel 依赖解析):
- 音频测试 2 个套件、36 个用例通过。
- 新增 35 个回归用例运行于基线 0493b52 的音频实现:24 个失败、11 个通过;运行于修复后实现全部通过。
- H5 全部测试:30 个套件、278 个用例通过。
验证边界:Jest/JSDOM 受控原生事件,未验证真实音频播放、真实浏览器或真机;未重新执行 package/全仓构建或独立类型检查(仓库 Jest 配置关闭 TS diagnostics)。
3c398a6 to
b9e0a46
Compare
这个 PR 做了什么?
H5 InnerAudioContext 的 offXxx 把省略的 callback 替换为新的空函数,导致已注册的回调无法移除。十类音频事件均可复现,offError/offStop 还会绕过 CallbackManager 的无参清空路径。
为原生 Audio 事件登记用户回调:不传 callback 时移除该事件的全部用户监听,传 callback 时保留指定移除行为。DOM 事件继续使用原生 EventTarget,保留事件参数、this、重复注册去重及分发期间移除的行为。offError/offStop 直接把可选参数交给原有 CallbackManager。
首次播放处理单独注册,不受 offPlay() 清空用户监听影响,startTime 仍在第一次 play 时应用。destroy 同时解绑登记的 DOM 回调和内部 play 监听,清理新增的登记引用。
Closes #19590
这个 PR 是什么类型?
这个 PR 涉及以下平台:
接口语义依据
快手官方 InnerAudioContext 文档与腾讯云音频官方文档明确规定,省略 callback 移除该事件的全部监听;抖音 offError 文档也明确区分有参和无参行为。Taro 现有类型允许 callback 省略。
验证
pnpm --filter @tarojs/taro-h5 run test:ci --watchman=false:30 个套件、278 个用例通过,退出码 0。pnpm --filter @tarojs/taro-h5 run build:通过,退出码 0;存在未修改的 previewImage/Swiper 类型及 Sass 弃用告警。pnpm build:通过,退出码 0;存在未修改文件的类型、组件及循环依赖等构建告警。Node.js 22.18.0 / pnpm 10.0.0。分支独立基于上游 main
0493b5251da,不包含 Vue v-model 等其他修复。未修改依赖或锁文件,构建生成的无关 definition 变更已清理。验证使用受控原生事件,没有真实音频播放、浏览器或真机验证。不改变共享 CallbackManager 的分发语义,也不宣称完整解决历史 #14447 的全部场景。
Summary by CodeRabbit
startTime定位不再依赖用户注册的播放监听,添加或移除用户监听不会影响该定位行为。