Repository navigation
Conversation
youtube-video-element and vimeo-video-element use media-played-ranges-mixin,
which defines `onSeeking()` and `onSeeked({ time })` methods on the element.
ce-la-react assigns props that exist on the element prototype as properties,
so the user's handlers replaced those methods: `onSeeked` was called with
`{ time }`, `onSeeking` with no arguments, and the element's `played` ranges
tracking broke.
Player now keeps these two handlers out of the props passed to the active
player and attaches them as native `seeking`/`seeked` event listeners, so
every player receives the event object as the types describe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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 #2031
Problem
With the YouTube and Vimeo players,
onSeekedis called with{ time: number }andonSeekingwith no arguments, instead of the event object their types describe.youtube-video-elementandvimeo-video-elementusemedia-played-ranges-mixin, which definesonSeeking()andonSeeked({ time })methods on the element. Thece-la-reactwrapper assigns any prop that already exists on the element prototype as a property instead of adding an event listener, so the user's handlers replaced those methods. As a result:onSeekedreceives{ time }, andonSeekingreceivesundefinedplayedranges tracking stops working, because its internal methods are goneOther players (HTML, HLS, DASH, Mux, …) already pass a real event, so I fixed the runtime rather than changing the types as suggested in the issue.
Change
In
src/Player.tsx:onSeekingandonSeekedare no longer passed down to the active player as props.Playerattaches them as nativeseeking/seekedlisteners in its ref callback. Handlers are read from a ref, so passing new handler functions on re-render doesn't re-add the listeners.if (!Player) return nullearly return, so the hook isn't called conditionally.props[key as keyof typeof props]replaceskeyof ReactPlayerProps:propsinsideforwardRefdoesn't includeref, which caused a TS7053 error with newer@types/react.Testing
test/Player.tsx:onSeeking/onSeekedreceive the dispatched native event (HTML player).onSeekedmethod), the handlers aren't passed as props, the element's own method is left intact, and the user's handler receives the event. This test fails without the fix.npm test,biome lint src/,tscandnpm run buildpass.npm start) with a YouTube and a Vimeo URL: seeking now logs anEventforonSeeking/onSeekedinstead ofundefined/{ time }.Before / after
Before: https://www.loom.com/share/cba9431547fc404fbfaeab284fdd4ab9
After: https://www.loom.com/share/446f14036e09418ea5f65f2768cf95fa