mclintprojects / actioncable-vue

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

Connection not closed after unmounting app #79

Open iuri-gg opened 1 year ago

iuri-gg commented 1 year ago

Describe the bug I am using actioncable-vue with Vue 3 app. When I call app.unmount(), ActionCable connection is not terminated.

To Reproduce Steps to reproduce the behaviour:

  1. Create new Vue 3, mount it, and subscribe to an action cable channel.
  2. call app.unmount();
  3. Observer action cable websocket connection is not closed

Expected behaviour ActionCable websocket connection should close after vue app unmounts.

Plugin version (please complete the following information): 2.5.1

Additional context I create and destroy Vue 3 apps multiple times on one page and that causes multiple action cable connections to stay open to the server, even though only one app is mounted at a time.

mackmm145 commented 7 months ago

basing off of this

https://github.com/mclintprojects/actioncable-vue/issues/66#issuecomment-1280319481

i added onBeforeUnmount to the imports and also added

  onBeforeUnmount(() => {
    cable.unsubscribe( 'MyChannel' )
    cable._removeChannel( 'MyChannel', instance.uid )
  })

there's no disconnected message, but it's removed from the subscriptions list.