alibaba / alibaba/ice

微应用监听主应用发送的消息,调用off取消监听不成功

Open
#6,959 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
18.6k
Forks
2.1k
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

主应用通过这两种方式给微应用传递消息:
import { store as starkDataStore, event } from '@ice/stark-data';

event?.emit(MQTT_MESSAGE, { topic, message: JSON.parse(message.toString()) });
starkDataStore?.set(MQTT_MESSAGE, { topic, message: JSON.parse(message.toString()) });

在微应用中:
```
starkEvent.on(MQTT_MESSAGE, ({ topic, message }) => {
console.log('航班动态 收到主应用推送过来的消息', topic, message);
onReceivedMqttMessage({ topic, message });
});

starkEvent.off(MQTT_MESSAGE, () => {
console.log('航班动态 主应用推送过来的消息监听被移除');
});
```
starkEvent.off没起作用,反复执行starkEvent.on,主应用发送一次消息,会多次进入starkEvent.on的回调方法

### Expected behavior

starkEvent.off(MQTT_MESSAGE, () => {
console.log('航班动态 主应用推送过来的消息监听被移除');
});
能够正常取消监听

### Actual behavior

_No response_

### Version of ice.js

"@ice/app": "3.4.10"

### Content of build.json or ice.config.mts

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the @ice/stark-data event.on and event.off entry points and reproduce the main-app to micro-app message flow shown in the report. The work is done when removing the listener prevents repeated callbacks after multiple registrations; the issue does not mention a specific file or test.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.