From a7bed1e872d3170d5bc088f3078008250ba533f1 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 6 Dec 2016 02:52:14 +0000 Subject: [PATCH] Customize: Prevent infinite full refresh from occurring when selective refresh falls back for a nav menu that has items excluded from rendering via filtering. Merges [39510] onto 4.7 branch. Fixes #38612 for 4.7. git-svn-id: https://develop.svn.wordpress.org/branches/4.7@39511 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/customize-preview-nav-menus.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/js/customize-preview-nav-menus.js b/src/wp-includes/js/customize-preview-nav-menus.js index 3876e4415c..27c525107b 100644 --- a/src/wp-includes/js/customize-preview-nav-menus.js +++ b/src/wp-includes/js/customize-preview-nav-menus.js @@ -15,7 +15,19 @@ wp.customize.navMenusPreview = wp.customize.MenusCustomizerPreview = ( function( * Initialize nav menus preview. */ self.init = function() { - var self = this; + var self = this, synced = false; + + /* + * Keep track of whether we synced to determine whether or not bindSettingListener + * should also initially fire the listener. This initial firing needs to wait until + * after all of the settings have been synced from the pane in order to prevent + * an infinite selective fallback-refresh. Note that this sync handler will be + * added after the sync handler in customize-preview.js, so it will be triggered + * after all of the settings are added. + */ + api.preview.bind( 'sync', function() { + synced = true; + } ); if ( api.selectiveRefresh ) { // Listen for changes to settings related to nav menus. @@ -32,7 +44,7 @@ wp.customize.navMenusPreview = wp.customize.MenusCustomizerPreview = ( function( * this can trigger an infinite fallback refresh when the nav menu item lacks any valid items. */ if ( setting.get() && ! setting.get()._invalid ) { - self.bindSettingListener( setting, { fire: true } ); + self.bindSettingListener( setting, { fire: synced } ); } } ); api.bind( 'remove', function( setting ) {