Make WordPress Core

Changeset 39112


Ignore:
Timestamp:
11/03/2016 05:06:17 AM (10 years ago)
Author:
westonruter
Message:

Customize: Prevent syncing unmodified settings from controls into preview to guard against triggering an infinite reload due to selective refresh fallback behavior.

If a value is sanitized in PHP and differs from the JS value in the pane, a change event for the setting is triggered upon refresh. This should be avoided since the value just came from the server as being sanitized. This also fixes periodic issue where selective refresh happens immediately after a full refresh.

Fixes #37032.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/customize-controls.js

    r39010 r39112  
    43004300
    43014301                        synced.settings = api.get();
     4302                        synced['settings-modified-while-loading'] = previewer.settingsModifiedWhileLoading;
    43024303                        if ( 'resolved' !== previewer.deferred.active.state() || previewer.loading ) {
    43034304                                synced.scroll = previewer.scroll;
     
    44224423                 */
    44234424                refresh: function() {
    4424                         var previewer = this;
     4425                        var previewer = this, onSettingChange;
    44254426
    44264427                        // Display loading indicator
     
    44354436                                container:  previewer.container
    44364437                        });
     4438
     4439                        previewer.settingsModifiedWhileLoading = {};
     4440                        onSettingChange = function( setting ) {
     4441                                previewer.settingsModifiedWhileLoading[ setting.id ] = true;
     4442                        };
     4443                        api.bind( 'change', onSettingChange );
     4444                        previewer.loading.always( function() {
     4445                                api.unbind( 'change', onSettingChange );
     4446                        } );
    44374447
    44384448                        previewer.loading.done( function( readyData ) {
  • trunk/src/wp-includes/js/customize-preview.js

    r39060 r39112  
    655655
    656656                api.preview.bind( 'sync', function( events ) {
     657
     658                        /*
     659                         * Delete any settings that already exist locally which haven't been
     660                         * modified in the controls while the preview was loading. This prevents
     661                         * situations where the JS value being synced from the pane may differ
     662                         * from the PHP-sanitized JS value in the preview which causes the
     663                         * non-sanitized JS value to clobber the PHP-sanitized value. This
     664                         * is particularly important for selective refresh partials that
     665                         * have a fallback refresh behavior since infinite refreshing would
     666                         * result.
     667                         */
     668                        if ( events.settings && events['settings-modified-while-loading'] ) {
     669                                _.each( _.keys( events.settings ), function( syncedSettingId ) {
     670                                        if ( api.has( syncedSettingId ) && ! events['settings-modified-while-loading'][ syncedSettingId ] ) {
     671                                                delete events.settings[ syncedSettingId ];
     672                                        }
     673                                } );
     674                        }
     675
    657676                        $.each( events, function( event, args ) {
    658677                                api.preview.trigger( event, args );
Note: See TracChangeset for help on using the changeset viewer.