knockout/knockout — pull request #1081 by mbest (2013-12-21 00:20:37+00:00)
Title: options placeholder always re-added when update binding fires

In the options update function, the captionPlaceholder variable is always assigned a new instance of an empty object.

This instance is then unshifted to the start of the filteredArray.

However when the array are compared ( from setDomNodeChildrenFromArrayMapping ), the old placeholder and the new placeholder objects are different instances of an empty objects

This caused the array comparer to delete the old placeholder and add a new placeholder, ultimately removing the old option element and adding a new option element.

This is un-necessary and can easily be eliminated by always using the same instance of the empty object ( whether globally or per DOM element ).

What triggered this investigation and finding is that we use Select2 to wrap the select element and we have element focus issues as it rebuilds the droplist if you immediately leave an element that (ultimately) causes a options binding update. I'm raising an issue with them as well as the problem still existing if the options legitimately change.