Unable to get mutation to trigger subscription because EventEmitter not being shared
Hey folks,
Been struggling with this for a few hours now hopelessly and trying random things - read all related posts in this forum, on github issues, and stackoverflow - and still don't understand what is going on.
I have a next app with a custom HTTP server and using tRPC. WSLink etc is all fine - i'm doing everything the proper way.
I have a router with these two functions:
I've added a bunch of console logs to help explain.
So, in my logs I see that when the app loads up I get a WS Connection to the server.
On the client side, I have
But, when I send a message, the mutation fails to trigger the subscription because it logs
I thought it was because maybe somehow multiple
this did not help either. using this
Been struggling with this for a few hours now hopelessly and trying random things - read all related posts in this forum, on github issues, and stackoverflow - and still don't understand what is going on.
I have a next app with a custom HTTP server and using tRPC. WSLink etc is all fine - i'm doing everything the proper way.
I have a router with these two functions:
I've added a bunch of console logs to help explain.
So, in my logs I see that when the app loads up I get a WS Connection to the server.
On the client side, I have
trpc.chat.onNewMessage.useSubscription which console logs {names: []} first and then {names: ['onNewMessage']} as it should based on the code for the router.But, when I send a message, the mutation fails to trigger the subscription because it logs
{namesSendMsg: []} i.e. for some reason it does;n't recognize the attached listenerI thought it was because maybe somehow multiple
EventEmitter instances are being created due to HMR - so I did a workaround similar to what we do with Prisma for next dev mode:src/eventEmitter.ts:this did not help either. using this
wsee everywhere doesn't change anything. im lost and have no idea WHY there are supposedly two different event emitter instances being used here?