Skip to content

fix: apply content prop changes to the running player - #41

Open
jwbrandon wants to merge 3 commits into
mainfrom
fix/playlist-updates
Open

fix: apply content prop changes to the running player#41
jwbrandon wants to merge 3 commits into
mainfrom
fix/playlist-updates

Conversation

@jwbrandon

@jwbrandon jwbrandon commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

The setup config was built once in the constructor and never reapplied, so changing playlist left the old media playing — consumers had to force a remount with a changing key. Playlist changes now go through the player's load() method from componentDidUpdate, compared by value so an equal-but-new array does not reload, and ignored when empty so late-arriving content cannot blank out a playing player.

Two related fixes fell out of it: the setup config is now built from the props current when setup runs, so props changing during the library load are no longer lost; and event-listener re-subscription moved out of shouldComponentUpdate, which returned false afterwards and dropped any playlist change in the same update — the common case, since inline handlers get a new identity every parent render. Keeping the side effect out of shouldComponentUpdate also honours React's requirement that it stay pure: a render that React starts and then discards must not have already told the player to load.

file is deliberately excluded from the live path: reloading it means rebuilding a playlist item, which would drop sibling top-level item options such as image and tracks. It and every other config option stay setup-time only, which the README now documents along with the key-remount workaround.

Supersedes #40, and carries over its stronger test coverage and its load() type declaration.

Closes #20

The setup config was built once in the constructor and never reapplied,
so changing playlist or file left the old media playing. Consumers had
to force a remount with a changing key.

Push content changes through the player's load() method from
componentDidUpdate, comparing playlist by value so a fresh but equal
array does not reload. Build the setup config from the props current
when setup runs, so props that change while the library loads are no
longer lost.

Event listeners were re-subscribed inside shouldComponentUpdate, which
then returned false. That dropped any content change arriving in the
same update — the common case, since inline handlers get a new identity
on every parent render. Move that work to componentDidUpdate. The test
asserting shouldComponentUpdate returns false for event-prop changes now
expects true, matching the corrected behavior.

Other config options are still setup-time only; document that and the
key-remount workaround.

Closes #20
Reloading a changed `file` meant rebuilding a playlist item from the top
level config, which silently drops the sibling item options this package
forwards without knowing their schema — image, tracks, title. Drop `file`
from the live path and document it as setup-time only, alongside every
other config option.

Also ignore an empty or absent playlist, so content that arrives later
cannot blank out a player that is already playing.
Carries over the stronger checks from the parallel PR on this issue:
unit tests for deepEqual, exact assertions on load's call list rather
than "was called with", a structural-equality case with nested tracks,
and a table over every empty playlist shape.

Also declares load() on the player API type, and documents that
once<Event> handlers are subscribed at mount only.
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