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

undefined is not an object (evaluating 'screen.orientation.removeEventListener') #3395

Open
vaughn-xyz opened this issue Nov 13, 2024 · 1 comment

Comments

@vaughn-xyz
Copy link

Our version in package.json --- 8.17.6

We have reports of user's encountering the above error which seems to stem from use-measure (imported in Canvas). From the source, it would appear as though there are enough logic gates to make sure this wouldn't throw but surprisingly in our build it seems some of these checks are removed.

This is what gets compiled at build time:

// cleanup current scroll-listeners / observers
function removeListeners() {
  if (state.current.scrollContainers) {
    state.current.scrollContainers.forEach(element => element.removeEventListener('scroll', scrollChange, true));
    state.current.scrollContainers = null;
  }
  
  if (state.current.resizeObserver) {
    state.current.resizeObserver.disconnect();
    state.current.resizeObserver = null;
  }
  
  if (state.current.orientationHandler) {
    screen.orientation.removeEventListener('orientationchange', state.current.orientationHandler);
  }
}

Yet the source looks like:

// cleanup current scroll-listeners / observers
  function removeListeners() {
    if (state.current.scrollContainers) {
      state.current.scrollContainers.forEach((element) => element.removeEventListener('scroll', scrollChange, true))
      state.current.scrollContainers = null
    }

    if (state.current.resizeObserver) {
      state.current.resizeObserver.disconnect()
      state.current.resizeObserver = null
    }

    if (state.current.orientationHandler) {
      if ('orientation' in screen && 'removeEventListener' in screen.orientation) {
        screen.orientation.removeEventListener('change', state.current.orientationHandler)
      } else if ('onorientationchange' in window) {
        window.removeEventListener('orientationchange', state.current.orientationHandler)
      }
    }
  }

Most specifically, it looks like support is dropped for if ('orientation' in screen && 'removeEventListener' in screen.orientation). While I will investigate our build line to see why it is dropped, this could be a bigger support issue and maybe a different logic gate should be used to ensure it doesn't throw

@vaughn-xyz
Copy link
Author

FWIW could an alpha build be done with this change in the source?

/* @preserve */
if ('orientation' in screen && 'removeEventListener' in screen.orientation) {
  screen.orientation.removeEventListener('change', state.current.orientationHandler)
} else if ('onorientationchange' in window) {
  window.removeEventListener('orientationchange', state.current.orientationHandler)
}

Probably need to add /* @preserve */ to both remove and add. I am having difficulties testing if this fixes the problem as I currently cannot reproduce it, only some uses have reported this

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

No branches or pull requests

1 participant