Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed conditions on window.removeEventLister to avoid breaking on react-native #781

Merged
merged 4 commits into from
Sep 29, 2021

Conversation

vishalnarkhede
Copy link
Contributor

CLA

  • I have signed the Stream CLA (required).
  • Code changes are tested

Description of the changes, What, Why and How?

We have this function within js client's connection class:

  _removeConnectionListeners = () => {
    if (
      typeof window !== 'undefined' &&
      window != null &&
      window.addEventListener != null
    ) {
      window.removeEventListener('offline', this.onlineStatusChanged);
      window.removeEventListener('online', this.onlineStatusChanged);
    }
  };

We call this function as part of disconnect logic. Although window is not a react-native thing, it just happens that some external dependencies can introduce it within global variable in react-native, causing our if checks to fail. Also clearly we are checking window.addEventListener before executing removeEventListener, which is a false check.

E.g., following piece of code within react-native replicates the issue.

global.window = {
  addEventListener: () => null,
  removeEventListener: null,
};

Changelog

  • Fixed the empty check on window.addEventListener and window.removeEventListener

@github-actions
Copy link
Contributor

github-actions bot commented Sep 29, 2021

Size Change: +441 B (0%)

Total Size: 250 kB

Filename Size Change
dist/browser.es.js 54.7 kB +111 B (0%)
dist/browser.full-bundle.min.js 30.1 kB +13 B (0%)
dist/browser.js 55.4 kB +103 B (0%)
dist/index.es.js 54.8 kB +111 B (0%)
dist/index.js 55.4 kB +103 B (0%)

compressed-size-action

@vishalnarkhede vishalnarkhede merged commit 73c7183 into master Sep 29, 2021
@vishalnarkhede vishalnarkhede deleted the vishal/remove-connection-listener-fix-1 branch September 29, 2021 12:49
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.

None yet

2 participants