[p5.js 2.0+ Bug Report]: assigning MediaElement.src leaves stale <source> children, so reading src returns the old source
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 24k
- Forks
- 3.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 25
Description
Most appropriate sub-area of p5.js?
DOM
p5.js version
2.x main (4b096e2)
Actual vs expected behavior
The src setter on p5.MediaElement removes existing <source> children with a forward index loop over the live HTMLCollection, which skips every other child as the collection reindexes:
const v = createVideo(['a.mp4', 'b.webm']);
v.src = 'c.mp4';
v.elt.childElementCount; // actual 2 (leftover b.webm + c.mp4), expected 1
v.src; // actual ends with 'b.webm' (getter returns children[0].src), expected 'c.mp4'
So after assigning a new source, reading v.src reports the old one, and the media element still lists the stale source first. The same code exists in 1.x, so this is longstanding rather than a 2.x regression.
Steps to reproduce
Outputs above are from executed runs against current main via the DOM unit test harness (the two new tests fail on unfixed code with expected 2 to deeply equal 1 and expected false to be true).
Note
I have a fix ready (iterate the live collection backwards, with a comment) plus 2 regression tests in the createVideo suite; the DOM suite passes 14 with it. Filing for approval per the contributing guide; will open the PR once approved.
Contributor guide
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 with the p5.MediaElement src setter and the createVideo DOM unit test suite mentioned in the issue. Run the DOM tests, then verify that assigning a new source leaves one source child and that reading src returns the new URL; the issue notes that regression tests already exist in the proposed fix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100