mclintprojects / actioncable-vue

A Vue plugin that makes integrating Rails Action Cable dead-easy.
MIT License
182 stars 37 forks source link

TypeError : cannot read property 'received' of undefined #34

Closed laurentmahieu closed 4 years ago

laurentmahieu commented 4 years ago

TypeError : cannot read property 'received' of undefined

Expected behaviour Hi, I join the project recently. We are using actioncable-vue, we received message. Everything seems to be ok. But in our sentry we get an error ( screenshot. ).

According to Sentry, the problem should come from node_modules/actioncable-vue/dist/actioncablevue.js. Someone got this problem? someone could explain, where could problem come from ?

Screenshots

Capture d’écran 2020-09-29 à 12 23 28
mclintprojects commented 4 years ago

That error looks like it's trying to find a subscription so it can call the received callback on it but in your case, the subscription doesn't seem to exist.

Kindly share code snippets of your channels object and you subscribing and I just might be able to spot the problem.

laurentmahieu commented 4 years ago

Thank you ! I have several more or less complex channels, I don't know which one is problematic. here is an example of a simple: channels: { RoomChannel: { connected() {}, rejected() {}, received(data) { if (data.hasOwnProperty("content")) { this.messages.push(data); this.scollToBottom(); } }, disconnected() {} } },

And here my subscribing: ActionCableConnect() { let urlConnect = '${ config.ws_url }cable?Okta-Access-Token=${getAccessToken()}&Okta-Id-Token=${getIdToken()}'; Vue.use(ActionCableVue, { debug: config.websocket_debug, debugLevel: "all", connectionUrl: urlConnect, connectImmediately: true }); },

mclintprojects commented 4 years ago

I think you should look through your subscriptions. You seem to be making at least one incorrect subscription.

vijaypemmaraju commented 1 year ago

For anyone who runs into this in the future, this is why we were seeing it:

  1. Our backend was upgraded to rails 6, but our client js library was still on actioncable@5.x
  2. Users not signed into our app were receiving a message to the client that looks like this {"type":"disconnect","reason":"unauthorized","reconnect":false}
  3. This wasn't not being handled correctly by the 5.x version of the library and hence throwing this error.

We were able to resolve the issue by upgrading to @rails/actioncable@6.x