Skip to content

Fix: useAnnotationKeyboardControls works without WaveformPlaylistProvider (#509)

Choose a tag to compare

@naomiaro naomiaro released this 28 Jun 01:21
4ddfded

Fixes a crash when using useAnnotationKeyboardControls outside a WaveformPlaylistProvider — e.g. the MediaElement path (MediaElementPlaylistProvider). PR #509.

Published packages

Package Version
@waveform-playlist/browser 13.1.3

What changed

useAnnotationKeyboardControls called usePlaylistData() unconditionally to read samplesPerPixel / sampleRate (a v11 "read from context" refactor). usePlaylistData() throws outside WaveformPlaylistProvider, so any MediaElement consumer wiring keyboard annotation controls crashed on mount with usePlaylistData must be used within WaveformPlaylistProvider.

  • Added usePlaylistDataOptional() — returns null instead of throwing when there is no WaveformPlaylistProvider ancestor. Exported for MediaElement-path consumers.
  • useAnnotationKeyboardControls now accepts optional samplesPerPixel / sampleRate props (restoring the pre-v11 API the MediaElement path relies on) and falls back to the WaveformPlaylist context when omitted. These values feed only optional auto-scroll, so the hook degrades gracefully when neither source is present.

Regression tests: the hook renders and navigates without a WaveformPlaylistProvider, plus a peerDependencies guard that fails if any package uses workspace:* in peerDependencies (the exact-pin footgun fixed in #508).