[wp-trac] [WordPress Trac] #26061: Customizer setting with array values incorrectly trigger as changed

WordPress Trac noreply at wordpress.org
Sat Nov 16 08:04:40 UTC 2013


#26061: Customizer setting with array values incorrectly trigger as changed
--------------------------+-----------------------------
 Reporter:  westonruter   |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Appearance    |    Version:  3.4
 Severity:  normal        |   Keywords:  has-patch
--------------------------+-----------------------------
 When a value is updated in the customizer models, it checks to see if the
 new value equals the old value, and if it does, then it short-circuits so
 as to not trigger the change callbacks if the new value is not different.
 This is working fine for scalar values (e.g. strings, booleans, numbers).
 However, for objects the test fails because two JavaScript object
 instances with the same contents are still different instances, and so
 they are not identical.

 The current equality test in `customize.Value` is:

 {{{#!js
 if ( null === to || this._value === to )
 }}}

 But if if the old value was an object `{"title":"Foo"}` and the new value
 is `{"title":"Foo"}`, then this conditional will fail because in
 JavaScript: `{"title":"Foo"} !== {"title":"Foo"}`. The result is that the
 value change callbacks will fire even the value didn't change, including
 when the customizer preview first loads as the settings get synced over.

 Fortunately, Underscore.js provides an `isEqual` function to compare two
 values to see if they have the same contents, and so we can use this
 instead:

 {{{#!js
 if ( null === to || _.isEqual( from, to ) ) {
 }}}

 Introduced in #19910 via r19995

 This bug was discovered in the course of developing the Widget Customizer
 plugin, as each widget instance is stored in a customizer setting, and
 these instances are JavaScript objects.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/26061>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list