Skip to content

[p5.js 2.0+ Bug Report]: assigning MediaElement.src leaves stale <source> children, so reading src returns the old source #9133

Description

@rajanpanth

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions