Accept a null source in MessageEventInit - #7470
Merged
jasnell merged 1 commit intoSep 23, 2026
Merged
Conversation
The HTML spec declares `MessageEventSource? source = null` in MessageEventInit, but the initializer typed source as jsg::Optional<jsg::Ref<MessagePort>>, which rejects null with a TypeError. Message events fired by a WebSocket or an EventSource have a null source, so copying one with `new MessageEvent(event.type, event)` threw. partysocket copies events that way. Compatibility: no flag. An omitted source and a MessagePort source behave as before; the only change is that null no longer throws. Before 79e36b4 the initializer read nothing but data, so code passing a null source worked until then, and this restores that.
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
danielmlr
marked this pull request as ready for review
September 22, 2026 18:42
jasnell
reviewed
Sep 23, 2026
jasnell
approved these changes
Sep 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lets
new MessageEvent()accept a null source again, as the HTML spec allows (MessageEventSource? source = null).Since #7053 the initializer types source as optional but not nullable, so null throws
TypeError: Incorrect type for the 'source' field on 'Initializer'. Every message event a WebSocket or EventSource fires has a null source, so copying one withnew MessageEvent(event.type, event)throws too. partysocket copies events that way, and emdash patches it to leave the source out.A port or an omitted source is unchanged. Before #7053 the initializer ignored the source altogether, so accepting null again needs no compatibility flag.
messageEventNullSourceinevents-test.jscovers an explicit null, a copy of a user-constructed event and a copy of aWebSocketPairmessage event. Without the fix it fails with the TypeError above in the@,@all-compat-flagsand@all-autogatesvariants; with it,bazel test //src/...passes on macOS arm64 (1951 tests, 8 skipped).