fix: wait for a library the consumer loads themselves - #42
Closed
jwbrandon wants to merge 1 commit into
Closed
Conversation
Two ways a mount could fail when the page supplies the player library. window.jwplayer was tested for truthiness, so a value that is present but not yet callable counted as ready and blew up inside setup with "window.jwplayer(...).setup is not a function". Require a function. Without a library prop, loadPlayer threw at once, so a player mounting before the consumer's own script tag ran never set up and never retried. Nothing fires an event when window.jwplayer is assigned, so poll for it for up to 10 seconds and clear the interval on both outcomes. The error for a genuinely missing library now arrives as a rejection after that timeout rather than a synchronous throw; componentDidMount catches both identically. Its test was updated to match. Closes #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes both ways a mount could fail when the page supplies the player library.
window.jwplayerwas tested for truthiness, so a value present but not yet callable counted as ready and failed insidesetup()with the error in the issue title; it now must be a function. And with nolibraryprop,loadPlayerthrew immediately, so a player mounting before the consumer's own script tag ran never set up and never retried — it now polls forwindow.jwplayerfor up to 10 seconds, clearing the interval on both outcomes.The error for a genuinely missing library now arrives as a rejection after that timeout instead of a synchronous throw.
componentDidMountcatches both identically, so consumer-visible behavior is unchanged apart from the delay; the test covering it was updated.Closes #12