Repository navigation
fix(runtime): 修复派发期间监听器变更导致重复调用或抛错 - #19593
Single-Dancer merged 3 commits into
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
监听器快照分发与回归测试 packages/taro-runtime/src/dom/element.ts, packages/taro-runtime/tests/event-dispatch-mutation.spec.ts |
dispatchEvent 遍历监听器快照,并在调用前检查监听器是否仍然注册。测试覆盖监听器移除、新增、重复注册、嵌套分发、once、传播停止、回调上下文、返回值及异常传播。 |
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested labels: T-weapp
Suggested reviewers: zakarycode, single-dancer
Merge Risk: 
Minimal · previous review 3e468
-
Listener mutations are handled using a snapshot. No merge-blocking issue was identified.
Pre-merge checks: 
5
-
Full details: Docstring Coverage
-
Explanation
No eligible functions found in the changed files. Skipping docstring coverage check. 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 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
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.
我是兔子,轻敲事件铃,
快照列好监听者的名字。
已移除的回调不再登场,
新来的等下一轮再出发。
嵌套派发读最新名单,
胡萝卜旁,测试全通过。
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #19593 +/- ##
=======================================
Coverage 57.93% 57.93%
=======================================
Files 470 470
Lines 26006 26008 +2
Branches 6524 6524
=======================================
+ Hits 15066 15068 +2
- Misses 9006 9105 +99
+ Partials 1934 1835 -99
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
3e46857 to
7793a88
Compare
…ime-dispatch-listener-mutation' of https://github.com/Jarvis636431/taro into fix/runtime-dispatch-listener-mutation
这个 PR 做了什么?
runtime DOM 的 dispatchEvent 直接倒序遍历可变监听器数组。回调取消其他监听器会改变下标,使当前回调重复执行;once 回调先解绑再移除其他监听器时,还可能读取 undefined._stop 并抛错。例如注册 first/second/third,third 取消 first,原实现得到 third/third/second。
派发开始时保存注册快照,调用前按包装器身份检查注册是否仍存在。保留原有倒序调用,跳过尚未调用就被移除的注册;新增注册留到下轮,嵌套派发读取最新列表。移除后重新注册同一用户回调不会复活本轮旧注册。
Closes #19592
这个 PR 是什么类型?
这个 PR 涉及以下平台:
验证
pnpm --filter @tarojs/runtime run test:ci --maxWorkers=2:22 文件通过,307 用例通过、1 跳过。Node.js 26.8.1 下通过,并在 Node.js 22.14.0 下重跑通过;pnpm 10.0.0。范围与限制
分支基于官方 main
10002ad884e,仅修改派发实现并新增测试,不改变监听器注册顺序或公共 API。与已合并 #19583 的 once 身份/解绑修复、#19586 的 H5 CallbackManager 快照分发属于不同实现。每次派发增加一次数组复制,并对快照中的注册查询当前数组。未运行全工作区构建、开发者工具、真机或完整 React/Vue 小程序应用验证。
Summary by CodeRabbit