-
Notifications
You must be signed in to change notification settings - Fork 541
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
The "event" argument must be an instance of Event. Received an instance of Event (WebSocket + ws) #2663
Comments
Closing because it's the issue in the I suspect that due to the Node.js version support they promise, they ended up re-implementing |
Strangely, even if I modify |
I don't understand. In the example |
@lpinca |
Here's a detailed call stack:
At its core, it's class identity issue ( |
There is no listener for the |
@lpinca there's a listener for the |
But you are adding it to the the undici |
I apologize, I extracted my issue scenario incorrectly 👍 Will update to prevent further confusion. |
I don't see how this is related to |
the repro works fine for me, is there an example where it doesn't? |
I think they are doing something like websockets/ws#1818 but I see nothing related to |
error is coming from: function fireEvent (e, target, eventConstructor = Event, eventInitDict) {
const event = new eventConstructor(e, eventInitDict) // eslint-disable-line new-cap
target.dispatchEvent(event)
}
fireEvent('open', <websocket instance>) I can only see this being an issue if Event is being overridden (a la jest). I don't think this is an undici issue either without more info. |
@KhafraDev, like I suspected, this isn't an issue with Undici. It simply surfaces through it. The issue is in the |
Can you please share a minimal test case? The one in the issue description works correctly. websockets/ws#1818 has nothing to do with this unless you take a |
Since ws' Event is similar to the spec one, it should be possible to take the attributes from ws' Event and create a node Event from that. |
Reproduction case
See the following errors during the test run:
This reproduction case is a part of the Interceptors library. Note that the interceptor itself doesn't affect The test in question will produce the same error even if you remove the interceptor part from it, which leads me to believe something else is the root cause here. More contextI learned that Undici also implements its own events but they do extend the global However, that's not the case. Here's when Undici emits its own Lines 96 to 102 in e30f200
If I check Line 48 in e30f200
console.log(event instanceof Event)
This instance check later on results in the Node.js error during the event validation here: I would be grateful if you point me in the right direction and explain why is that instance check failing. |
This is likely an environment problem. Standalone, Undici events pass the instanceof check: const { MessageEvent } = require('undici/lib/websocket/events.js')
console.log(new MessageEvent('message') instanceof Event)
// true I will try to see if this has anything to do with the test runner I'm using. |
Root causeThis error was happening due to JSDOM. It's always JSDOM. Looks like the global Thank you everyone for help here. I appreciate it a lot. |
Bug Description
When Undici calls
fireEvent
with theMessageEvent
received from the server constructed via thews
package, the following error is thrown byinternals/event_target
:Reproducible By
Expected Behavior
The
MessageEvent
dispatched viafireEvent
does not throw an error.Logs & Screenshots
Environment
Additional context
Here's the check that Node performs before throwing that error:
https://github.com/nodejs/node/blob/64c6d97463c29bade4d6081683dab2cd7cda298d/lib/internal/event_target.js#L751
I suspect that the
MessageEvent
provided by thews
package doesn't extend the globalEvent
correctly, and thus fails theinstanceof
check. I still think it's worth opening the issue in Undici for discoverability even if the root cause will end up to be elsewhere.The text was updated successfully, but these errors were encountered: