matrix-org / matrix-org/matrix-widget-api
`handleMessage` default behaviour leads to superfluous errors
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 95
- Forks
- 24
- Avg merge
- 16h 16m
- Merged PRs (30d)
- 1
Description
On each side of the widget transport, there are `handleMessage` functions such as:
```js
private handleMessage(ev: CustomEvent) {
const actionEv = new CustomEvent(`action:${ev.detail.action}`, {
detail: ev.detail,
cancelable: true,
});
this.emit(`action:${ev.detail.action}`, actionEv);
if (!actionEv.defaultPrevented) {
switch (ev.detail.action) {
case WidgetApiToWidgetAction.SupportedApiVersions:
return this.replyVersions(ev.detail);
case WidgetApiToWidgetAction.Capabilities:
return this.handleCapabilities(ev.detail);
case WidgetApiToWidgetAction.UpdateVisibility:
return this.transport.reply(ev.detail, {}); // ack to avoid error spam
case WidgetApiToWidgetAction.NotifyCapabilities:
return this.transport.reply(ev.detail, {}); // ack to avoid error spam
default:
return this.transport.reply(ev.detail, {
error: {
message: "Unknown or unsupported action: " + ev.detail.action,
},
});
}
}
}
```
At the moment, the library seems setup (based on the guide on the repo home page) to require widget developers to call `ev.preventDefault()` on anything they listen to and craft their own reply, even when it's effectively a one way notification and an empty reply is just fine.
As shown above a few random notification-like actions (`UpdateVisibility`, `NotifyCapabilities`) are auto-replied, while all others (e.g. `SendEvent`) default to sending back an error, even though the data was emitted and probably processed by the widget anyway.
I would suggest flipping around the default behaviour to sending empty data and dropping the error path. After all, the data has been emitted already, and (most likely) processed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the widget transport handleMessage implementations shown in the issue and read the repository guide describing event handling and replies. Compare the current default error path with the existing acknowledgements for UpdateVisibility and NotifyCapabilities. Done means unsupported or notification-like actions receive the intended empty reply without requiring listeners to prevent the default, with the error behavior and API compatibility clarified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100