Skip to content

Remove MessagePort's close event - #13016

Merged
annevk merged 1 commit into
whatwg:mainfrom
nicolo-ribaudo:remove-messageport-close
Oct 2, 2026
Merged

annevk merged 1 commit into
whatwg:mainfrom
nicolo-ribaudo:remove-messageport-close

Conversation

@nicolo-ribaudo

@nicolo-ribaudo nicolo-ribaudo commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

As discussed in #12957. Note that I have no interest in working on re-adding the event, but the commit description should have enough pointer for somebody else that might.

Closes #10201, closes #12797, closes #12957

Commit message:

Remove MessagePort's close event

This is a revert of cc2634f (it's not a "clean" revert because of some other changes that happened in the meantime).

This means that this patch also restores the older GC semantics: a port is not easily GC-able, it is not exlicitly disentangled when the other half's owner document is destroyed, and relies on polling to see if the other half is still alive. I believe this matches Firefox's behavior, which is also what I believe the discussion in #10201 leads to.

Note that browsers have all different GC semantics (according to Claude):

  • Chromium makes a port uncollectable only if it's already started
  • Firefox does not collect them
  • WebKit keeps the port uncollectable only if it has a message listener

Given that no browser ships the close events this revert is probably the best thing to do; if somebody in the future wants to reintroduce it some relevant discussions are:


(See WHATWG Working Mode: Changes for more details.)


/document-lifecycle.html ( diff )
/index.html ( diff )
/indices.html ( diff )
/web-messaging.html ( diff )

Comment thread source

@nicolo-ribaudo nicolo-ribaudo Oct 1, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The disentangle steps were introduced in the original onclose PR, but it's nice to have a dfn for the various places that disentangle ports.

@zcorpan

zcorpan commented Oct 1, 2026

Copy link
Copy Markdown
Member

If this matches current implementations, that satisfies the implementer interest item. Should have tests to verify the lack of an event and event handler IDL attribute.

@annevk annevk added the removal/deprecation Removing or deprecating a feature label Oct 2, 2026
Comment thread source Outdated
Comment thread source Outdated
@nicolo-ribaudo

Copy link
Copy Markdown
Member Author

If this matches current implementations, that satisfies the implementer interest item.

Well, it kind of matches implementations. No implementation ships close (Chrome did implement it, but it's behind I believe a test-only flag).

However all implementation disagree on GC semantics, which this PR restores to the pre-close-event state. None implemented the post-close-event GC behavior, and only Firefox has the old one.

Should have tests to verify the lack of an event and event handler IDL attribute.

Done

This is a revert of cc2634f (it's not
a "clean" revert because of some other changes that happened in the
meantime).

This means that this patch also restores the older GC semantics: a
port is not easily GC-able, it is not explicitly disentangled when
the other half's owner document is destroyed, and relies on polling to
see if the other half is still alive. I believe this matches Firefox's
behavior, which is also what I believe the discussion in whatwg#10201 leads to.

Note that browsers have all different GC semantics (according to Claude):
- Chromium makes a port uncollectable only if it's already started
- Firefox does not collect them
- WebKit keeps the port uncollectable only if it has a message listener

Given that no browser ships the `close` events this revert is probably
the best thing to do; if somebody in the future wants to reintroduce it
some relevant discussions are:
- whatwg#1766
- whatwg#9933
- whatwg#10201
- whatwg#12797
- whatwg#12957
@nicolo-ribaudo
nicolo-ribaudo force-pushed the remove-messageport-close branch from c86a6a2 to dda60d9 Compare October 2, 2026 09:56
annevk pushed a commit to web-platform-tests/wpt that referenced this pull request Oct 2, 2026
@annevk
annevk merged commit 5facb53 into whatwg:main Oct 2, 2026
2 checks passed
@nicolo-ribaudo
nicolo-ribaudo deleted the remove-messageport-close branch October 2, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

removal/deprecation Removing or deprecating a feature

Development

Successfully merging this pull request may close these issues.

MessagePort should probably fire close event from a task Restrict when MessagePort's onclose event can fire

3 participants