Skip to content

Conversation

@majeed-platogo
Copy link

The block below is useful for handling autoconnection/disconnection when users leave or enter the tab

if (phxWindow && phxWindow.addEventListener) {
      phxWindow.addEventListener("pagehide", (_e) => {
        if (this.conn) {
          this.disconnect();
          awaitingConnectionOnPageShow = this.connectClock;
        }
      });
      phxWindow.addEventListener("pageshow", (_e) => {
        if (awaitingConnectionOnPageShow === this.connectClock) {
          awaitingConnectionOnPageShow = null;
          this.connect();
        }
      });
    }

But in our case, It clashes with our own listener that does this among other things. That's why we're introducing disableWindowEventListeners to make this optional

@majeed-platogo majeed-platogo force-pushed the change/optional-window-event-listeners branch from f0d39f0 to 82e69d7 Compare April 16, 2025 11:43
* setItem(keyName, keyValue) { this.storage[keyName] = keyValue }
* }
*
* @param {boolean} [opts.disableWindowEventListeners] - Boolean that determines if window event listeners should be active
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add this, I'd rather call it something like disableAutoDisconnectOnPageHide to be explicit. LiveView passes unknown options to Phoenix and uses a lot of window event listeners, so this might be confusing.

cc @chrismccord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants