cpunion/react-actioncable-provider

Web-socket unsubscribes and doesn't reconnect

sandmule opened this issue · 2 comments

I've suffered from an issue that once a message is received and the state changes, triggering a render, it sends an unsubscribe command, followed by a subscribe command. 95% of the time it doesn't reconnect, I'm unsure if this is an asynchronous issue or intended behaviour.

To get around this, I've had to render the ActionCableConsumer just once:

    this.acc || (this.acc = <ActionCableConsumer
             channel='NotificationsChannel'
             onReceived={this.handleReceived}
           />);

Is there a better way of doing this? Or am I missing something?

Got the same problem.
As soon as I use setState() inside componentDidMount the component will re-render.
In the Rails console I can see that the client subscribes and then unsubscribes. (wrong order!)
onConnected and onDisconnected events won't fire on re-render though!
No messages sent from the server are coming through :'(

  public render() {
      return (
        <ActionCableConsumer
          channel={channelObject}
          onConnected={this.handleConnected}
          onDisconnected={this.handleDisconnected}
          onReceived={this.handleReceived}
          onRejected={this.handleRejected}
          ref={(obj: any) => {
            this.actionControllerObj = obj;
          }}
        >
          <div className="live-chat">
            <div className="chat-comments">{this.renderMessages()}</div>
          </div>
        </ActionCableConsumer>
      );
    }

Thanks for the workaround! Also getting this