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

广播订阅事件中无法执行指定了 componentId/componentName 的动作 #11536

Open
BeMxself opened this issue Jan 22, 2025 · 1 comment

Comments

@BeMxself
Copy link
Contributor

问题表现

我监听了一个广播,把一些组件设为 disabled,但是在从 6.7.0 升级到 6.10.0 之后出现以下报错:

Image

问题分析

经过排查,原因是 6.8.0 之后,增加了 bindGlobalEventForRenderer 的方式来绑定全局广播事件

bc.onmessage = e => {
const {eventName, data} = e.data;
const rendererEvent = createRendererEvent(eventName, {
env: renderer?.props?.env,
nativeEvent: eventName,
scoped: renderer?.context,

在触发广播事件的时候,这里会把 renderer.context 属性当作事件对象 context.scoped 属性,传递给 runActions。

但因为很多 renderer 的 context 属性是空对象(空对象,而不是空),导致这里无法获取 targetComponent:

let targetComponent = cmptFlag
? event.context.scoped?.[
action.componentId ? 'getComponentById' : 'getComponentByName'
](cmptFlag)
: renderer;

因为这里面涉及到一些底层机制,我不确定从何入手,所以把问题抛出来看看怎么解决?

@2betop

@BeMxself
Copy link
Contributor Author

补充新情况:
当监听广播的 onEvent 位于 service 上时,可以正常触发,印证了前面的分析,即出错的直接原因是 renderer 的 context 属性是空对象。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant