From c7a57d2391727696f25a4254cddf2caf23e30251 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 26 May 2016 16:45:07 -0700 Subject: [PATCH] Let post_name changes skip doing any partial refreshing by default --- js/customize-preview-posts.js | 21 ++++++++++++++++++--- php/class-wp-customize-posts-preview.php | 3 +++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/js/customize-preview-posts.js b/js/customize-preview-posts.js index d387eb1..98f3d63 100644 --- a/js/customize-preview-posts.js +++ b/js/customize-preview-posts.js @@ -64,9 +64,24 @@ } } else { partial = new api.previewPosts.PostFieldPartial( schema.id, { params: schema.params } ); - partial.renderContent = function() { - api.selectiveRefresh.requestFullRefresh(); - return true; + + /** + * Suppress wasted partial refreshes for partials that lack selectors. + * + * For example, since the post_name field is not normally + * displayed, suppress refreshing changes. + * + * @returns {jQuery.promise} Promise. + */ + partial.refresh = function refreshWithoutSelector() { + var deferred = $.Deferred(); + if ( this.params.fallbackRefresh ) { + api.selectiveRefresh.requestFullRefresh(); + deferred.resolve(); + } else { + deferred.reject(); + } + return deferred.promise(); }; api.selectiveRefresh.partial.add( partial.id, partial ); } diff --git a/php/class-wp-customize-posts-preview.php b/php/class-wp-customize-posts-preview.php index bc1f1d1..99b9b45 100644 --- a/php/class-wp-customize-posts-preview.php +++ b/php/class-wp-customize-posts-preview.php @@ -521,6 +521,9 @@ public function get_post_field_partial_schema( $field_id = '' ) { 'post_title' => array( 'selector' => '.entry-title', ), + 'post_name' => array( + 'fallback_refresh' => false, + ), 'post_content' => array( 'selector' => '.entry-content', ),