Skip to content

fix: wait for a library the consumer loads themselves - #42

Closed
jwbrandon wants to merge 1 commit into
mainfrom
fix/external-library
Closed

fix: wait for a library the consumer loads themselves#42
jwbrandon wants to merge 1 commit into
mainfrom
fix/external-library

Conversation

@jwbrandon

Copy link
Copy Markdown
Contributor

Fixes both ways a mount could fail when the page supplies the player library. window.jwplayer was tested for truthiness, so a value present but not yet callable counted as ready and failed inside setup() with the error in the issue title; it now must be a function. And with no library prop, loadPlayer threw immediately, so a player mounting before the consumer's own script tag ran never set up and never retried — it now polls for window.jwplayer for 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. componentDidMount catches both identically, so consumer-visible behavior is unchanged apart from the delay; the test covering it was updated.

Closes #12

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
@jwbrandon jwbrandon closed this Aug 10, 2026
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.

window.jwplayer(...).setup is not a function

1 participant