Skip to content

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

Merged
merged 1 commit into from
Jun 24, 2025

Conversation

yogeshbhutkar
Copy link
Contributor

@yogeshbhutkar yogeshbhutkar commented Jun 3, 2025

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

  1. Create a new post.
  2. Insert a Video block.
  3. Try attaching duplicate tracks to the video block
  4. Confirm that it's not possible to attach duplicate tracks to the video block.

Testing Instructions for Keyboard

Same.

Screencast

PR.mov

@yogeshbhutkar yogeshbhutkar changed the title Video Block: Guard Against Duplicate Tracks Video Block: Guard against duplicate tracks Jun 3, 2025
}

const trackIndex = tracks.length;
onChange( [ ...tracks, { label: title || '', src: url } ] );
Copy link
Contributor Author

@yogeshbhutkar yogeshbhutkar Jun 3, 2025

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)

@yogeshbhutkar yogeshbhutkar marked this pull request as ready for review June 3, 2025 09:13
Copy link

github-actions bot commented Jun 3, 2025

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: yogeshbhutkar <[email protected]>
Co-authored-by: Mamaduka <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano added [Type] Code Quality Issues or PRs that relate to code quality [Block] Video Affects the Video Block [Type] Bug An existing feature does not function as intended and removed [Type] Code Quality Issues or PRs that relate to code quality labels Jun 4, 2025
@Mamaduka Mamaduka self-requested a review June 5, 2025 08:11
@Mamaduka
Copy link
Member

@yogeshbhutkar, do you mind rebasing this PR on top of the latest trunk?

@yogeshbhutkar yogeshbhutkar force-pushed the fix/key-validation-track-ui branch from ffdf1c2 to cf003ac Compare June 24, 2025 08:01
Copy link
Member

@Mamaduka Mamaduka left a 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!

@Mamaduka Mamaduka merged commit 3b30d40 into WordPress:trunk Jun 24, 2025
60 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.1 milestone Jun 24, 2025
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Video Affects the Video Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Video Block: Unguarded duplicate track insertion triggers unique key validation error
3 participants