Open bicknellr opened 5 years ago
When both the multi and fallback-selection attributes are set on an <iron-selector> in HTML, the first property flush throws in IronMultiSelectableBehavior.
multi
fallback-selection
<iron-selector>
IronMultiSelectableBehavior
When these two attributes are used together, the _checkFallback(fallbackSelection) observer in IronSelectableBehavior runs before the multiChanged observer in IronMultiSelectableBehavior. multiChanged would normally update this._selection.multi, which IronSelection uses to determine whether or not to return the full array of selected items or just the first item. However, _checkFallback is called first, which eventually calls down into _updateSelected, which reads this.multi and calls _selectMulti. _selectMulti assumes it's safe to consider the result of this._selection.get() to be an array, but this._selection.multi has not been updated yet and this._selection.get() returns undefined rather than an empty array, causing an error to be thrown on getting length.
_checkFallback(fallbackSelection)
IronSelectableBehavior
multiChanged
this._selection.multi
IronSelection
_checkFallback
_updateSelected
this.multi
_selectMulti
this._selection.get()
undefined
length
The initial property flush succeeds without throwing.
The initial property flush throws an error on the first connectedCallback.
connectedCallback
https://js-kt759o.stackblitz.io/ (https://stackblitz.com/edit/js-kt759o)
In HTML <iron-selector> with the multi and fallback-selection attributes set.
Description
When both the
multi
andfallback-selection
attributes are set on an<iron-selector>
in HTML, the first property flush throws inIronMultiSelectableBehavior
.When these two attributes are used together, the
_checkFallback(fallbackSelection)
observer inIronSelectableBehavior
runs before themultiChanged
observer inIronMultiSelectableBehavior
.multiChanged
would normally updatethis._selection.multi
, whichIronSelection
uses to determine whether or not to return the full array of selected items or just the first item. However,_checkFallback
is called first, which eventually calls down into_updateSelected
, which readsthis.multi
and calls_selectMulti
._selectMulti
assumes it's safe to consider the result ofthis._selection.get()
to be an array, butthis._selection.multi
has not been updated yet andthis._selection.get()
returnsundefined
rather than an empty array, causing an error to be thrown on gettinglength
.Expected outcome
The initial property flush succeeds without throwing.
Actual outcome
The initial property flush throws an error on the first
connectedCallback
.Live Demo
https://js-kt759o.stackblitz.io/ (https://stackblitz.com/edit/js-kt759o)
Steps to reproduce
In HTML
<iron-selector>
with themulti
andfallback-selection
attributes set.Browsers Affected