Skip to content

fix: pass native events to onSeeking and onSeeked (#2031) - #2058

Open
super0605 wants to merge 1 commit into
cookpete:masterfrom
super0605:fix/seek-event-handlers
Open

super0605 wants to merge 1 commit into
cookpete:masterfrom
super0605:fix/seek-event-handlers

Conversation

@super0605

@super0605 super0605 commented Oct 22, 2026 •

Copy link
Copy Markdown

Fixes #2031

Problem

With the YouTube and Vimeo players, onSeeked is called with { time: number } and onSeeking with no arguments, instead of the event object their types describe.

youtube-video-element and vimeo-video-element use media-played-ranges-mixin, which defines onSeeking() and onSeeked({ time }) methods on the element. The ce-la-react wrapper 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:

  • onSeeked receives { time }, and onSeeking receives undefined
  • the element's played ranges tracking stops working, because its internal methods are gone

Other 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:

  • onSeeking and onSeeked are no longer passed down to the active player as props.
  • Player attaches them as native seeking / seeked listeners in its ref callback. Handlers are read from a ref, so passing new handler functions on re-render doesn't re-add the listeners.
  • The ref callback is now created before the if (!Player) return null early return, so the hook isn't called conditionally.
  • props[key as keyof typeof props] replaces keyof ReactPlayerProps: props inside forwardRef doesn't include ref, which caused a TS7053 error with newer @types/react.

Testing

  • Added two tests in test/Player.tsx:
    • onSeeking/onSeeked receive the dispatched native event (HTML player).
    • With a player that mimics youtube/vimeo-video-element (an element with its own onSeeked method), 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/, tsc and npm run build pass.
  • Manually in the demo (npm start) with a YouTube and a Vimeo URL: seeking now logs an Event for onSeeking/onSeeked instead of undefined / { time }.

Before / after

Before: https://www.loom.com/share/cba9431547fc404fbfaeab284fdd4ab9
After: https://www.loom.com/share/446f14036e09418ea5f65f2768cf95fa

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

No deployments
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.

Incorrect type definitions for onSeeked and onSeeking callbacks

1 participant