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

destroy() throws an error #66

Open
jenni-divvito opened this issue Aug 21, 2017 · 0 comments
Open

destroy() throws an error #66

jenni-divvito opened this issue Aug 21, 2017 · 0 comments

Comments

@jenni-divvito
Copy link

jenni-divvito commented Aug 21, 2017

Hello,

Not sure if this issue really belongs here or in the react-youtube-player repo, but unmounting a parent component of the React Youtube Player component throws an error at current (however the error appears to be in youtube-player to me, and the best way I can see to fix it is also in here, which is why I figured I would raise the issue here).

So the issue appears to be that when the parent component is unmounted, react-youtube-player's calls stopVideo, and youtube-player in turn passes this call on (once the player promise resolves) to youtubes iFrame API. However, by the time the promise resolves and the method is called, the player iFrame no longer exists and we get: "Uncaught (in promise) Error: The YouTube player is not attached to the DOM."

I believe the best fix for this would be (in YoutubePlayer.js:120):

functions[functionName] = (...args) => {
        return playerAPIReady
        .then((player) => {
          // Only act if the iFrame is still contained in the DOM
          if (document.comparePosition(player.a) & 16) {
            // eslint-disable-next-line no-warning-comments
            // TODO: Just spread the args into the function once Babel is fixed:
            // https://github.com/babel/babel/issues/4270
            //
            // eslint-disable-next-line prefer-spread
            return player[functionName].apply(player, args);
          }
        });
      };

thoughts?

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