diff --git a/assets/js/hooks/js_view.js b/assets/js/hooks/js_view.js index 6b90bb6c0..001872728 100644 --- a/assets/js/hooks/js_view.js +++ b/assets/js/hooks/js_view.js @@ -146,6 +146,11 @@ const JSView = { this.props = this.getProps(this); }, + disconnected() { + // Reinitialize on reconnection + this.el.removeAttribute("id"); + }, + destroyed() { window.removeEventListener("message", this._handleWindowMessage); diff --git a/assets/js/hooks/session.js b/assets/js/hooks/session.js index b6a16d9be..af33f7f7f 100644 --- a/assets/js/hooks/session.js +++ b/assets/js/hooks/session.js @@ -233,6 +233,10 @@ const Session = { disconnected() { // Reinitialize on reconnection this.el.removeAttribute("id"); + + // If we reconnect, a new hook is mounted and it becomes responsible + // for leaving the channel when destroyed + this.keepChannel = true; }, destroyed() { @@ -246,7 +250,9 @@ const Session = { setFavicon("favicon"); - leaveChannel(); + if (!this.keepChannel) { + leaveChannel(); + } }, getProps() {