Repository navigation
fix: initialize preloaded media duration and buffered state - #2737
Open
wanxiankai wants to merge 1 commit into
Open
wanxiankai wants to merge 1 commit into
wanxiankai wants to merge 1 commit into
Conversation
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.
Description
Fixes #2642.
When audio metadata loads before React attaches its event handlers,
useAudiomisses the initialdurationchangeevent and leavesstate.durationat0. This also clamps everycontrols.seek()call to the start of the recording.useVideoshares the same implementation.Read
durationandbufferedalongside the existing media-state snapshot on mount and whensrcchanges. Keep the initial duration at0whilereadyStateis belowHAVE_METADATA. This also clears the previous source's metadata when a replacement source has not loaded yet. No public API or dependency changes.Add 16 regression tests covering audio/video, props/element inputs, preloaded metadata, later duration events, event forwarding, seeking, and source changes. Update both hook references. The new tests produce 12 failures and 4 passing controls against unchanged upstream code, and all 16 pass with this change.
Validation:
jest --runInBand --watchman=false).tsc --noEmit, CommonJS build (tsc), and ESM build (tsc -m esNext --outDir esm) passed.<audio preload="metadata">, then hydrate after metadata is available. Upstream reports duration0, buffered[], and seeking to0.75stays at0; this change reports duration2, buffered[{ start: 0, end: 2 }], and seeking reaches0.75. No synthetic media metadata was used in this comparison.AI assistance was used for investigation, implementation, and validation.
Type of change
Checklist
yarn test) — equivalent Jest invocation above, with Watchman disabled for this environmentyarn lint). Fix it withyarn lint:fixin case of failure.yarn lint:types).