Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RootPortal组件内部的点击事件不响应 #13312

Closed
zhipenglin opened this issue Feb 16, 2023 · 4 comments · Fixed by #14836 or #14885
Closed

RootPortal组件内部的点击事件不响应 #13312

zhipenglin opened this issue Feb 16, 2023 · 4 comments · Fixed by #14836 or #14885
Labels
bug Something isn't working F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@zhipenglin
Copy link

相关平台

微信小程序

复现仓库

https://github.com/zhipenglin/taro-root-portal-bug.git
小程序基础库: 2.30.0
使用框架: React

复现步骤

放在RootPortal组件内部的组件,当RootPortal组件外部有onClick事件监听的时候,内部组件的onClick不能正常响应

期望结果

RootPortal组件的内部组件的onClick正常响应

实际结果

RootPortal组件的内部组件的onClick不能正常响应

环境信息

 Taro CLI 3.6.0 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 16.18.0 - C:\Program Files\nodejs\node.EXE
      npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Feb 16, 2023
@TheKonka
Copy link
Member

https://developers.weixin.qq.com/miniprogram/dev/component/root-portal.html
小程序原生也是不响应,除非你直接点击内部组件

@zhipenglin
Copy link
Author

zhipenglin commented Feb 17, 2023

是这样,如果RootPortal外部有View监听onClick事件,RootPortal内部View监听的事件就不响应,如果把外部的VIew的onClick去掉,内部的View监听就可以生效了,不是说内部View onClick要RootPortal外部的View生效

所有操作都点击的是RootPortal内部绑定onClick事件的View,不是点击外部要里面响应

@taro-bot2 taro-bot2 bot removed the to be closed label Feb 17, 2023
@TheKonka TheKonka added the bug Something isn't working label Feb 17, 2023
@TheKonka
Copy link
Member

TheKonka commented Feb 17, 2023

!isParentBinded(node, type) ||

/**
* 往上寻找组件树直到 root,寻找是否有祖先组件绑定了同类型的事件
* @param node 当前组件
* @param type 事件类型
*/
export function isParentBinded (node: TaroElement | null, type: string): boolean {
let res = false
while (node?.parentElement && node.parentElement._path !== ROOT_STR) {
if (node.parentElement.__handlers[type]?.length) {
res = true
break
}
node = node.parentElement
}
return res
}

因为有祖先元素监听了onClick事件, isParentBinded返回true,导致没有及时回调

@Fried-dumplings
Copy link

现在还是会有这个问题,我用原生小程序是没有这个问题,求大佬麻烦看一下 @TheKonka

TheKonka added a commit to TheKonka/taro that referenced this issue Nov 15, 2023
Chen-jj added a commit that referenced this issue Nov 24, 2023
#14836)

* fix(runtime): fix event listener not working in root-portal if the parent node also listening

#13312

* chore: 优化代码

---------

Co-authored-by: chenjiajian <798095202@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
3 participants