angular / components Public
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
bug(youtube-player): YT.Player is not a constructor #20598
Comments
|
@dwolverton great report, feel free to send a PR with your proposed solution |
|
I tried looking into this, but I wasn't able to reproduce it, even if I throttle the request for YouTube's API for long after the Angular app is done loading. I don't doubt that it's happening, but I have a hard time understanding what is going on, because the way we have the component set up is that it'll wait for As you mentioned, it can happen if |
fixes a race condition where window.YT would be truthy but window.YT.Player would not be ready. Fixes angular#20598
|
I'll try to have another look in the next few days to see if I can find a way to get a sample that reproduces it. |
|
I am having the same issue, can confirm that @dwolverton 's fix works ( made a pr in case it helps :) |
|
I have been able to create a stackblitz that reproduces and illustrates the issue. https://stackblitz.com/edit/components-issue-2tnqui?file=src%2Fapp%2Fexample-component.ts The example-components.ts file has three different points where the YoutubePlayer can be created by setting Also instructive is the YouTube API loading code itself... https://www.youtube.com/iframe_api I see that @Ronll made a pull request, but let me know if you need any more help from me. |
added a test to prevent reggression, the test mimicks a possible state of the YT object when loading, when window.YT exists but window.YT.Player does not. Fixes angular#20598
added a test to prevent reggression, the test mimics a possible state of the YT object when loading, when window.YT exists but window.YT.Player does not. Fixes angular#20598
* fix(youtube-player): YT.Player is not a constructor fixes a race condition where window.YT would be truthy but window.YT.Player would not be ready. Fixes #20598 * fix(youtube-player): YT.Player is not a constructor test added a test to prevent reggression, the test mimics a possible state of the YT object when loading, when window.YT exists but window.YT.Player does not. Fixes #20598
* fix(youtube-player): YT.Player is not a constructor fixes a race condition where window.YT would be truthy but window.YT.Player would not be ready. Fixes #20598 * fix(youtube-player): YT.Player is not a constructor test added a test to prevent reggression, the test mimics a possible state of the YT object when loading, when window.YT exists but window.YT.Player does not. Fixes #20598 (cherry picked from commit b0d0388)
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
* fix(youtube-player): YT.Player is not a constructor fixes a race condition where window.YT would be truthy but window.YT.Player would not be ready. Fixes angular#20598 * fix(youtube-player): YT.Player is not a constructor test added a test to prevent reggression, the test mimics a possible state of the YT object when loading, when window.YT exists but window.YT.Player does not. Fixes angular#20598
This is an intermittent exception due to a race condition.
The problem is in youtube-player.ts line 213. It checks
if (!window.YT)but window.YT exists before window.YT.Player exists. There is an intermediate loading state where YT.loaded = 0. I believe a solution could be to change this if toif (!window.YT || !window.TY.loaded)or alternativelyif (!window.YT || !window.TY.Player).Reproduction
This Stackblitz has similar code to our app where the problem is happening, however it did not reproduce the race condition for me. https://stackblitz.com/edit/components-issue-dkswjg?file=src%2Findex.html
Steps to reproduce:
Expected Behavior
The player shows the video.
Actual Behavior
The player did not load. An error is logged to the console.
ERROR TypeError: YT.Player is not a constructor
at youtube-player.js:529
at ZoneDelegate.invoke (zone-evergreen.js:364)
at Zone.run (zone-evergreen.js:123)
at NgZone.runOutsideAngular (core.js:27364)
at ScanSubscriber.syncPlayerState [as accumulator] (youtube-player.js:529)
at ScanSubscriber._tryNext (scan.js:49)
at ScanSubscriber._next (scan.js:42)
at ScanSubscriber.next (Subscriber.js:49)
at MapSubscriber._next (map.js:35)
at MapSubscriber.next (Subscriber.js:49)
Environment
Possibly some commenters on #19871 were seeing this same problem.
The text was updated successfully, but these errors were encountered: