option.selected suddenly changes to true for no reason




DOM: Core & HTML
2 months ago
a day ago


(Reporter: Andrea Giammarchi, Unassigned)


57 Branch

Firefox Tracking Flags

(Not tracked)



(1 attachment)



2 months ago
Created attachment 8932464 [details]

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36

Steps to reproduce:

I have used a diffing algorithm to update a <SELECT> element with fresh new options.

You can test the break down of the issue in this CodePen:

Actual results:

The <SELECT> shows a different selected options compared to any other browser. Nobody set the option.selected = true to the first item of the select.

Expected results:

The select should accept new option nodes, eventually flag as non selected the previously live selected one and **never** set selected = true to random nodes.


2 months ago
Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core
Comment hidden (offtopic)
Jessica knows more about <select> than I do so I'll needinfo her.

Anne, is it spec-compliant to set option.selected = true for the first item of the <select> element?
Flags: needinfo?(jjong)
Flags: needinfo?(annevk)
Comment hidden (obsolete)
Comment hidden (obsolete)

Comment 5

2 months ago
It seems Firefox does not implement this bit from the HTML Standard:

> If the multiple attribute is absent, whenever an option element in the select element's list of options has its selectedness set to true, and whenever an option element with its selectedness set to true is added to the select element's list of options, the user agent must set the selectedness of all the other option elements in its list of options to false.

Possibly there's some confusion with later requirements around manipulating the contents of select elements, but nothing supports Firefox's behavior.
Flags: needinfo?(annevk)
Also, this:

> If two or more option elements in the select element's list of options have their selectedness set to true
>  Set the selectedness of all but the last option element with its selectedness set to true in the list of options in tree order to false.

So, yes, it's a bug in Firefox. Let me get back to this later.
Assignee: nobody → jjong
Ever confirmed: true
Flags: needinfo?(jjong)
Priority: -- → P2
I remembered when I was debugging, it was because we call CheckSelecSomething [1] in HTMLSelectElement::SetOptionsSelectedByIndex, so maybe we should call the function with mask NO_RESELECT somewhere.
A little hint for anyone who is taking this bug in the future. :)

[1] https://searchfox.org/mozilla-central/rev/2031c0f517185b2bd0e8f6f92f9491b3410c1f7f/dom/html/HTMLSelectElement.cpp#961
Assignee: jessi3py → nobody
You need to log in before you can comment on or make changes to this bug.