Skip to content

fix: load new content when the playlist prop changes - #40

Closed
jwbrandon wants to merge 1 commit into
mainfrom
fix/playlist-update
Closed

fix: load new content when the playlist prop changes#40
jwbrandon wants to merge 1 commit into
mainfrom
fix/playlist-update

Conversation

@jwbrandon

Copy link
Copy Markdown
Contributor

This PR will...

Load the new content when the playlist prop changes, instead of leaving the player on the old media. The playlist is compared structurally on each update and handed to player.load(), so the player is reused rather than remounted.

Why is this Pull Request needed?

Fixes #20 — the config was built once in the constructor, so a playlist change after mount never reached the player. Consumers had to force a remount with a key prop.

Are there any points in the code the reviewer needs to double check?

  • The config is refreshed before the "no player yet" guard in shouldComponentUpdate, so a playlist that resolves while the library is still downloading reaches setup().
  • A playlist that is empty or nullish is ignored, so content arriving later does not blank out a playing player.
  • Only playlist is applied after setup. file/sources would need a playlist-item key allowlist to reload without dropping siblings like image and tracks, which this package deliberately avoids; the README now documents them as setup-time only.
  • The reload is a side effect in shouldComponentUpdate, matching how event handlers are already handled there. componentDidUpdate would miss updates where a handler and the playlist change together.

Are there any Pull Requests open in other repos which need to be merged with this?

No.

Addresses Issue(s):

#20

The config was generated once in the constructor, so a playlist change
after mount never reached the player and it kept playing the old media.
Consumers had to force a remount with a key prop.

The playlist is now compared structurally on every update and handed to
player.load(), reusing the player. A playlist that is empty or nullish is
ignored, so content that resolves later does not blank out playback, and
a change that lands while the library is still loading reaches setup().

Closes #20
@jwbrandon

Copy link
Copy Markdown
Contributor Author

Superseded by #41, which takes the same approach — structural comparison of the playlist, handed to player.load() — but runs the load from componentDidUpdate rather than shouldComponentUpdate. React requires shouldComponentUpdate to be pure, so a render that React begins and then discards must not already have told the player to load.

The stronger parts of this PR were carried over to #41: the load() declaration on JWPlayerApi, the deepEqual unit tests, exact assertions on load's call list, the structural-equality case with nested tracks, the table over every empty playlist shape, and the README note that once<Event> handlers are subscribed at mount only.

Closing in favour of #41. Thanks for the coverage — it made the surviving PR better.

@jwbrandon jwbrandon closed this Aug 10, 2026
@jwbrandon
jwbrandon deleted the fix/playlist-update branch August 10, 2026 21:17
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.

Player not updating when playlist attribute changes.

1 participant