option.selected suddenly changes to true for no reason

NEW
Unassigned

Status

()

Core
DOM: Core & HTML
P2
normal
2 months ago
a day ago

People

(Reporter: Andrea Giammarchi, Unassigned)

Tracking

57 Branch
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

2 months ago
Created attachment 8932464 [details]
firefox-bug.html

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:
https://codepen.io/WebReflection/pen/WXaeWj?editors=0010


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.

Updated

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
Status: UNCONFIRMED → ASSIGNED
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
Status: ASSIGNED → NEW
You need to log in before you can comment on or make changes to this bug.