-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Video Block: Guard against duplicate tracks #70295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Video Block: Guard against duplicate tracks #70295
Conversation
} | ||
|
||
const trackIndex = tracks.length; | ||
onChange( [ ...tracks, { label: title || '', src: url } ] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the file's title as the label makes more sense than falling back to an arbitrary default (such as 'English' in this case) when the label is empty. Since this is a minor change, I've included it as part of this small refactor.
P.S. I plan to refactor the use of defaults in tracks and introduce internal state management for the single track UI in a follow-up.
Ref. #70227 (comment)
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@yogeshbhutkar, do you mind rebasing this PR on top of the latest trunk? |
ffdf1c2
to
cf003ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works as expected. Thank you, @yogeshbhutkar!
Co-authored-by: yogeshbhutkar <[email protected]> Co-authored-by: Mamaduka <[email protected]>
What?
Closes #70294
This PR updates the media upload's
onSelect
handler to return early if the selected source already exists in the track list, and notifies the user about the duplicate entry.Why?
Since the source is used as the key when mapping tracks, duplicate entries trigger a React warning about non-unique keys.
How?
The
onSelect
handler prevents further processing if the selected source is already present.Testing Instructions
Testing Instructions for Keyboard
Same.
Screencast
PR.mov