fix(RN): enhance RN IntersectionObserver lifecycle and cleanup logic - #2585
Open
wangshunnn wants to merge 6 commits into
Open
fix(RN): enhance RN IntersectionObserver lifecycle and cleanup logic#2585wangshunnn wants to merge 6 commits into
wangshunnn wants to merge 6 commits into
Conversation
hiyuki
reviewed
Sep 11, 2026
| if (this._disconnected || relativeRect === IgnoreTarget) return | ||
| observeRects.forEach((observeRect, index) => { | ||
| if (observeRect === IgnoreTarget) return | ||
| if (this._disconnected || observeRect === IgnoreTarget) return |
Collaborator
Author
There was a problem hiding this comment.
这里是考虑业务可能在前一个节点的回调里调用 disconnect(),然后我先按断开后停止后续节点回调来处理了。我也一起验证下微信的表现。
Collaborator
Author
There was a problem hiding this comment.
微信真机上验证首个回调中断开后,其余节点不再回调,这里可以保留。
hiyuki
reviewed
Sep 11, 2026
| this.component._intersectionObservers = this.component._intersectionObservers || [] | ||
| this.component._intersectionObservers.push(this) | ||
|
|
||
| this._disconnected = false |
Collaborator
There was a problem hiding this comment.
需要测试微信的表现,disconnect之后是否还能重新建立观察对象
Collaborator
Author
There was a problem hiding this comment.
微信原生真机表现:先 observe() 再 disconnect() 后,原实例再次 observe() 会抛错;重新调用 relativeTo() 也会抛错,无法恢复观察。
hiyuki
reviewed
Sep 11, 2026
| this.observerRefs = null | ||
| this.relativeRef = null | ||
| this.callback = noop | ||
| this.previousIntersectionRatio = [] |
Collaborator
There was a problem hiding this comment.
这些小的属性重置没有必要啊,只需要执行 remove(this.component._intersectionObservers, this) 把根引用断掉自然就能被gc,保险起见在保留个this.component = null就可以,当然前提是微信当中的执行过disconnect后当前的intersectionObserver就再也不可用
Collaborator
Author
There was a problem hiding this comment.
已优化,真机验证了这个前提成立
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix (RN)
背景
排查 RN 曝光监听连续报错时,发现业务在滚动回调中反复创建 IntersectionObserver,未及时断开旧实例,导致实例累积并触发 Hermes 属性存储上限。
排查同时发现框架在主动断开和组件卸载时存在清理不完整的问题。本 PR 修复框架侧生命周期清理;业务侧反复创建 observer 的问题已同步业务方另行调整跟进。
修复内容
disconnect()完整移除注册及持有的引用,取消尚未执行的节流测量任务,忽略在途测量结果,确保断开后不再触发业务回调,并支持重复调用。验证
微信原生表现观察
本次真机环境:iOS 26.7、微信 8.0.76、基础库 3.17.2。