diff --git a/src/wp-includes/js/autosave.js b/src/wp-includes/js/autosave.js index 6cd6a47fd7..f339c94967 100644 --- a/src/wp-includes/js/autosave.js +++ b/src/wp-includes/js/autosave.js @@ -141,8 +141,8 @@ jQuery(document).ready( function($) { } // When connection is lost, keep user from submitting changes. - $(document).on('heartbeat-connection-lost.autosave', function( e, error ) { - if ( 'timeout' === error ) { + $(document).on('heartbeat-connection-lost.autosave', function( e, error, status ) { + if ( 'timeout' === error || 503 == status ) { var notice = $('#lost-connection-notice'); if ( ! wp.autosave.local.hasStorage ) { notice.find('.hide-if-no-sessionstorage').hide(); diff --git a/src/wp-includes/js/heartbeat.js b/src/wp-includes/js/heartbeat.js index 335a4f2d9d..f8e55886fa 100644 --- a/src/wp-includes/js/heartbeat.js +++ b/src/wp-includes/js/heartbeat.js @@ -45,7 +45,7 @@ window.wp = window.wp || {}; userActiveEvents, winBlurTimeout, frameBlurTimeout = -1, - hasConnectionError = false; + hasConnectionError = null; /** * Returns a boolean that's indicative of whether or not there is a connection error @@ -53,7 +53,7 @@ window.wp = window.wp || {}; * @returns boolean */ this.hasConnectionError = function() { - return hasConnectionError; + return !! hasConnectionError; }; if ( typeof( window.heartbeatSettings ) == 'object' ) { @@ -108,7 +108,7 @@ window.wp = window.wp || {}; } // Set error state and fire an event on XHR errors or timeout - function errorstate( error ) { + function errorstate( error, status ) { var trigger; if ( error ) { @@ -132,14 +132,20 @@ window.wp = window.wp || {}; break; } + if ( 503 == status && false === hasConnectionError ) { + trigger = true; + } + if ( trigger && ! self.hasConnectionError() ) { hasConnectionError = true; - $(document).trigger( 'heartbeat-connection-lost', [error] ); + $(document).trigger( 'heartbeat-connection-lost', [error, status] ); } } else if ( self.hasConnectionError() ) { errorcount = 0; hasConnectionError = false; $(document).trigger( 'heartbeat-connection-restored' ); + } else if ( null === hasConnectionError ) { + hasConnectionError = false; } } @@ -213,7 +219,7 @@ window.wp = window.wp || {}; connecting = false; next(); }).fail( function( jqXHR, textStatus, error ) { - errorstate( textStatus || 'unknown' ); + errorstate( textStatus || 'unknown', jqXHR.status ); self.error( jqXHR, textStatus, error ); }); }