WebKit / standards-positions

WebKit's positions on emerging web specifications
https://webkit.org/standards-positions/
242 stars 19 forks source link

Add a close event to MessagePort. #271

Open nononokam opened 11 months ago

nononokam commented 11 months ago

WebKittens

@annevk

Title of the spec

MessagePort close event

URL to the spec

https://html.spec.whatwg.org/multipage/web-messaging.html#message-ports

URL to the spec's repository

No response

Issue Tracker URL

https://github.com/whatwg/html/issues/1766

Explainer URL

https://github.com/fergald/explainer-messageport-close

TAG Design Review URL

No response

Mozilla standards-positions issue URL

No response

WebKit Bugzilla URL

No response

Radar URL

No response

Description

Currently, there is no timely and reliable way to detect when a MessagePort becomes disentangled. This makes it difficult to release resources associated with ports. Some users have used the unload event to detect disconnect, but it is deprecated. Therefore, The approach available now is to hold a MessagePort in WeakRef and periodically check if this port has been garbage collected by using deref() or to make use of a page-hide event, which is quite inefficient.
So, I propose adding a close event. For example, if there are two entangled ports, portA and portB, and portA is closed, the close event is fired on portB.

Ahmad-S792 commented 3 months ago

WebKit Bug - https://bugs.webkit.org/show_bug.cgi?id=267567

annevk commented 3 months ago

Note that there's an unresolved issue with this feature: https://github.com/whatwg/html/issues/10201.