Bug 1886276 Comment 0 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

### Description

Bug 1882835 introduced an issue where a `<menulist>` with `noinitialselection="true"` would have its internal state reset by the [connectedCallback()](https://searchfox.org/mozilla-central/rev/09b59a7de6848639f27297888889a06e97561074/toolkit/content/widgets/menulist.js#113-130) function if a race condition occurs in which the value is manually set _before_ the connected callback is invoked. 

This causes an issue where the external (UI) state shows the selected value, but the internal state thinks that no value is selected. In this scenario, when a new value is selected, the menu-list implementation does not realize that it should de-select the old value, because it thinks there was no value.

I didn't realize this issue until I started using it, because this race condition only occurs if a value is set before the callback is invoked, but the fix should be simple.

---

### Steps to implement

We just need to move the two calls that reset the internal state within [connectedCallback()](Bug 1882835 introduced an issue where a menulist with `noinitialselection="true"` would have its internal state reset by the [connectedCallback()](https://searchfox.org/mozilla-central/rev/09b59a7de6848639f27297888889a06e97561074/toolkit/content/widgets/menulist.js#127-128) function to do so in the [setInitialValue()](https://searchfox.org/mozilla-central/rev/09b59a7de6848639f27297888889a06e97561074/toolkit/content/widgets/menulist.js#291-294) function itself, after the optional early return.

---

### Tests to implement

* Simulate the race condition and ensure that only one menuitem is selected after the value changes.
### Description

Bug 1882835 introduced an issue where a `<menulist>` with `noinitialselection="true"` would have its internal state reset by the [connectedCallback()](https://searchfox.org/mozilla-central/rev/09b59a7de6848639f27297888889a06e97561074/toolkit/content/widgets/menulist.js#113-130) function if a race condition occurs in which the value is manually set _before_ the connected callback is invoked. 

This causes an issue where the external (UI) state shows the selected value, but the internal state thinks that no value is selected. In this scenario, when a new value is selected, the menu-list implementation does not realize that it should de-select the old value, because it thinks there was no value.

I didn't realize this issue until I started using it, because this race condition only occurs if a value is set before the callback is invoked, but the fix should be simple.

---

### Steps to implement

We just need to move the two calls that reset the internal state within [connectedCallback()](https://searchfox.org/mozilla-central/rev/09b59a7de6848639f27297888889a06e97561074/toolkit/content/widgets/menulist.js#127-128) function itself, after the optional early return.

---

### Tests to implement

* Simulate the race condition and ensure that only one menuitem is selected after the value changes.
### Description

Bug 1882835 introduced an issue where a `<menulist>` with `noinitialselection="true"` would have its internal state reset by the [connectedCallback()](https://searchfox.org/mozilla-central/rev/09b59a7de6848639f27297888889a06e97561074/toolkit/content/widgets/menulist.js#113-130) function if a race condition occurs in which the value is manually set _before_ the connected callback is invoked. 

This causes an issue where the external (UI) state shows the selected value, but the internal state thinks that no value is selected. In this scenario, when a new value is selected, the menu-list implementation does not realize that it should de-select the old value, because it thinks there was no value.

I didn't realize this issue until I started using it, because this race condition only occurs if a value is set before the callback is invoked, but the fix should be simple.

---

### Steps to implement

We just need to move the two calls that reset the internal state within [connectedCallback()](https://searchfox.org/mozilla-central/rev/09b59a7de6848639f27297888889a06e97561074/toolkit/content/widgets/menulist.js#127-128) function to instead be called within the [setInitialSelection()](https://searchfox.org/mozilla-central/rev/09b59a7de6848639f27297888889a06e97561074/toolkit/content/widgets/menulist.js#291-294) function itself, after the optional early return.

---

### Tests to implement

* Simulate the race condition and ensure that only one menuitem is selected after the value changes.

Back to Bug 1886276 Comment 0