Skip to content
This repository has been archived by the owner on Aug 24, 2018. It is now read-only.

Commit

Permalink
Merge pull request #181 from xwp/fix/save-race-condition
Browse files Browse the repository at this point in the history
Fix race condition if hitting Save & Publish button too quickly after entering text
  • Loading branch information
westonruter authored May 11, 2017
2 parents 8214b02 + 35fd8f5 commit 0e666fe
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions wp-admin/js/widgets/text-widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,28 @@ wp.textWidgets = ( function( $ ) {

control.editorFocused = false;
triggerChangeIfDirty = function() {
var updateWidgetBuffer = 300; // See wp.customize.Widgets.WidgetControl._setupUpdateUI() which uses 250ms for updateWidgetDebounced.
if ( editor.isDirty() ) {

/*
* Account for race condition in customizer where user clicks Save & Publish while
* focus was just previously given to to the editor. Since updates to the editor
* are debounced at 1 second and since widget input changes are only synced to
* settings after 250ms, the customizer needs to be put into the processing
* state during the time between the change event is triggered and updateWidget
* logic starts. Note that the debounced update-widget request should be able
* to be removed with the removal of the update-widget request entirely once
* widgets are able to mutate their own instance props directly in JS without
* having to make server round-trips to call the respective WP_Widget::update()
* callbacks. See <https://core.trac.wordpress.org/ticket/33507>.
*/
if ( wp.customize ) {
wp.customize.state( 'processing' ).set( wp.customize.state( 'processing' ).get() + 1 );
_.delay( function() {
wp.customize.state( 'processing' ).set( wp.customize.state( 'processing' ).get() - 1 );
}, updateWidgetBuffer );
}

editor.save();
textarea.trigger( 'change' );
}
Expand Down

0 comments on commit 0e666fe

Please sign in to comment.