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

Add a close event to MessagePort #914

Open
nononokam opened this issue Oct 24, 2023 · 4 comments
Open

Add a close event to MessagePort #914

nononokam opened this issue Oct 24, 2023 · 4 comments

Comments

@nononokam
Copy link

nononokam commented Oct 24, 2023

Request for Mozilla Position on an Emerging Web Specification

Other information

Currently, there is no timely and reliable way to detect when a MessagePort becomes disentangled, which makes it difficult to release resources associated with ports. This issue has a long discussion of the problem and potential solutions. 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.

@asutherland
Copy link
Member

I'm very positive on this; I would plan to mark us as positive on this absent any other feedback. There is a lot of good discussion in the issue and explainer, so if anyone has any questions, I would check both of those out first.

@zcorpan
Copy link
Member

zcorpan commented Nov 14, 2023

@smaug---- WDYT?

@smaug----
Copy link
Collaborator

Given that one can achieve this through WeakRefs already, I think this is reasonable.
But, this is only about MessagePort, do we want onclose also on Worker?

(unrelated fwiw, unload is not deprecated. That is a link to a chromium internal thing, not a spec level deprecation)

@asutherland
Copy link
Member

But, this is only about MessagePort, do we want onclose also on Worker?

whatwg/html#5869 tracks that, so I'd stick to treating that as a separate thing despite the normative and non-normative language around "DedicatedWorkerGlobalScope objects act as if they had an implicit MessagePort associated with them.".

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

No branches or pull requests

4 participants