From 1b5dd9b426c47ff111bf13fbc4dc4b2f84c58d7d Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Wed, 20 Apr 2022 05:55:06 +0000 Subject: [PATCH] Autosave: Compare heartbeat intervals in same unit. Move the conversion of `minimalInterval` to milliseconds to be grouped with the other time conversions from seconds to milliseconds. This fixes a bug in which the minimal and main intervals were compared after the former had been converted to milliseconds but the latter had not. This could cause the heatbeat interval to blow out to unexpectedly high values if the minimal interval was set. Props tabrisrp, sabernhardt, SergeyBiryukov, audrasjb. Fixes #54825. Built from https://develop.svn.wordpress.org/trunk@53226 git-svn-id: http://core.svn.wordpress.org/trunk@52815 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/heartbeat.js | 5 ++++- wp-includes/js/heartbeat.min.js | 2 +- wp-includes/version.php | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/wp-includes/js/heartbeat.js b/wp-includes/js/heartbeat.js index 4f71c1cab4..c6950ef7df 100644 --- a/wp-includes/js/heartbeat.js +++ b/wp-includes/js/heartbeat.js @@ -155,7 +155,7 @@ */ if ( options.minimalInterval ) { options.minimalInterval = parseInt( options.minimalInterval, 10 ); - settings.minimalInterval = options.minimalInterval > 0 && options.minimalInterval <= 600 ? options.minimalInterval * 1000 : 0; + settings.minimalInterval = options.minimalInterval > 0 && options.minimalInterval <= 600 ? options.minimalInterval : 0; } if ( settings.minimalInterval && settings.mainInterval < settings.minimalInterval ) { @@ -176,6 +176,9 @@ // Convert to milliseconds. settings.mainInterval = settings.mainInterval * 1000; settings.originalInterval = settings.mainInterval; + if ( settings.minimalInterval ) { + settings.minimalInterval = settings.minimalInterval * 1000; + } /* * Switch the interval to 120 seconds by using the Page Visibility API. diff --git a/wp-includes/js/heartbeat.min.js b/wp-includes/js/heartbeat.min.js index d301271068..6f422a8d1b 100644 --- a/wp-includes/js/heartbeat.min.js +++ b/wp-includes/js/heartbeat.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -!function(f,w){w.wp=w.wp||{},w.wp.heartbeat=new function(){var e,t,n,a,r=f(document),i={suspend:!1,suspendEnabled:!0,screenId:"",url:"",lastTick:0,queue:{},mainInterval:60,tempInterval:0,originalInterval:0,minimalInterval:0,countdown:0,connecting:!1,connectionError:!1,errorcount:0,hasConnected:!1,hasFocus:!0,userActivity:0,userActivityEvents:!1,checkFocusTimer:0,beatTimer:0};function o(){return(new Date).getTime()}function c(e){var t,n=e.src;if(!n||!/^https?:\/\//.test(n)||(t=w.location.origin||w.location.protocol+"//"+w.location.host,0===n.indexOf(t)))try{if(e.contentWindow.document)return 1}catch(e){}}function s(){i.hasFocus&&!document.hasFocus()?m():!i.hasFocus&&document.hasFocus()&&v()}function u(e,t){var n;if(e){switch(e){case"abort":break;case"timeout":n=!0;break;case"error":if(503===t&&i.hasConnected){n=!0;break}case"parsererror":case"empty":case"unknown":i.errorcount++,2