OpenCut-app / OpenCut-app/OpenCut

Fix race condition in timeline drag handlers when finding added media items

Open
#329 0 comments 1 reaction 0 assignees View on GitHub

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

Reported by: @simonorzel26

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.