OpenCut-app / OpenCut-app/OpenCut
Fix race condition in timeline drag handlers when finding added media items
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 89.8k
- Forks
- 8.9k
- PR merge metrics
- No merged PRs in 30d
Description
Description
A race condition exists in the timeline drag handlers when processing dropped files. The current implementation searches for added media items by matching name and URL, which can be unreliable if multiple items have the same name or if the state hasn't updated yet.
Location
File: apps/web/src/components/editor/timeline/timeline-drag-handlers.tsx
Lines: ~115-124
Issue
The code currently finds added media items like this:
const addedItem = currentMediaItems.find(
(item) =>
item.name === processedItem.name &&
item.url === processedItem.url,
);
This approach can fail when:
- Multiple items have the same name
- State updates are delayed
- Race conditions occur during processing
Proposed Solution
Use the returned ID from addMediaItem instead of searching by name and URL:
const mediaItemId = await addMediaItem(activeProject.id, processedItem);
const addedItem = currentMediaItems.find(
(item) => item.id === mediaItemId
);
References
- PR: https://github.com/OpenCut-app/OpenCut/pull/324
- Comment: https://github.com/OpenCut-app/OpenCut/pull/324#discussion_r2211935392
Reported by: @simonorzel26
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in apps/web/src/components/editor/timeline/timeline-drag-handlers.tsx around lines 115-124 and inspect how addMediaItem is called and how the returned value is used. Review PR #324 and its discussion for context. Done means dropped media items are identified reliably even with duplicate names or delayed state updates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100