Repository navigation
fix(shared): make Events#once fire exactly once - #19506
Conversation
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. Walkthrough
Changes一次监听器行为
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. 小兔挥耳检查事件线 Comment |
once 的 wrapper 先执行回调再调用 off 解绑,回调内如果再次 trigger 同一事件, wrapper 会在解绑前被重入并无限重复执行;回调抛错时 off 也不会执行,监听器 残留在链上,下一次 trigger 仍会命中。改为用 fired 标记保证回调只执行一次, 并把 off 放进 finally 保证异常路径也会解绑。
覆盖 symbol 事件名、多事件名、传入 context、回调内多次 trigger、 先重入再报错、空回调等路径,并断言回调报错后事件不再残留在监听链上 (这一条用于锁定 finally 中的 off,缺少它时仅靠 fired 标记也能通过)。 另把在修复前后都通过的用例标注为 control。
608377e to
44fb4c2
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #19506 +/- ##
=======================================
Coverage 54.63% 54.63%
=======================================
Files 464 464
Lines 25391 25391
Branches 6348 6325 -23
=======================================
Hits 13872 13872
- Misses 9505 9537 +32
+ Partials 2014 1982 -32
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Summary
Events#oncedetach a listener even when its callback throws.Decisions
A per-listener fired guard closes the re-entrancy window without changing general event dispatch.
finallypreserves exception propagation while ensuring the listener is removed on the throwing path.Not run: the full monorepo suite; the focused
@tarojs/sharedVitest suite was run on both base and change heads.AI assistance: this bug was found and the fix and tests were drafted with AI tooling in my workflow; the tests and checks above were executed as pasted. I'm responsible for the change and will handle review feedback.
Summary by CodeRabbit
Bug Fixes
Tests