Skip to content

Drop Zone Ops — Auto Duration Detection + Bug Fixes#2

Merged
cskonopka merged 1 commit intomainfrom
v2
Feb 23, 2026
Merged

Drop Zone Ops — Auto Duration Detection + Bug Fixes#2
cskonopka merged 1 commit intomainfrom
v2

Conversation

@cskonopka
Copy link
Contributor

Drop Zone Ops — Auto Duration Detection + Bug Fixes

Summary

Three focused improvements following the v2 merge: automatic video duration detection on file drop, a critical memory crash fix, and a UI count bug fix.


Changes

⏱ Auto Duration Detection

When you drop local video files into the Drop Zone, the app now automatically reads each file's duration and pre-fills it in the playlist — no manual entry required.

How it works:

  • On file drop, a temporary object URL is created pointing at the file in memory
  • A hidden <video> element loads just the metadata (not the full video)
  • The moment onloadedmetadata fires, duration is captured in seconds
  • URL.revokeObjectURL() is called immediately — file is released from memory
  • Item is added to the playlist with duration already set in MM:SS format

Scope:

  • Works for files dropped directly or browsed via file picker
  • Does not apply to typed paths, pasted URLs, or CSV/JSON imports (browser has no file access in those cases — duration remains blank for manual entry)
  • On read failure, falls back to 0 gracefully — no crash, no missing item

🐛 Critical Fix — Memory Crash on Large File Drops

The initial duration detection implementation caused a browser crash when dropping multiple files (reproduced with 198 files).

Root cause — two issues:

  1. onloadedmetadata and onerror handlers were not nulled after firing, allowing the browser to re-trigger them repeatedly on the same video element
  2. All files were processed simultaneously via forEach — every file created its own object URL and video element at the same time, holding everything in memory in parallel until the browser ran out of resources

Fix:

  • Files now process sequentially — each file only starts after the previous one has fully completed
  • Handlers are nulled immediately after firing (video.onloadedmetadata = null, video.onerror = null) before any other operations
  • video.src = '' and URL.revokeObjectURL() called in the same cleanup pass
  • One file in memory at a time, no re-triggers, no runaway loops

🐛 Fix — Header Item Count Shows "1 ITEM" on Empty Playlist

After clearing the playlist or deleting all items, the header status pill incorrectly showed 1 ITEM instead of 0 ITEMS.

Root cause: The render() function has an early return when the playlist is empty. updateStats() and updatePreview() were both called before that early return, but updatePill() was only called later in the function — after the early return had already exited, so the header count never updated.

Fix: Added updatePill() to the empty state early return block alongside the existing updateStats() and updatePreview() calls.


Files Changed

File Change
index.html Auto duration detection, sequential processing, empty state pill fix

Testing

  • Dropped single file → duration auto-detected ✅
  • Dropped 10+ files → all durations detected sequentially, no crash ✅
  • Cleared playlist → header shows 0 ITEMS
  • Deleted last remaining item → header shows 0 ITEMS
  • Dropped unsupported file type → falls back to 0 duration, item added normally ✅

@cskonopka cskonopka merged commit 713b85e into main Feb 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant