Skip to content

Commit d5cbd3d

Browse files
committed
Heartbeat: Handle race condition in wp-auth-check where heartbeat-tick may fire before DOMContentLoaded.
Developed in #10624 Follow-up to [23805], [50547]. Props westonruter, ArtZ91, siliconforks. See #23295. Fixes #64403. git-svn-id: https://develop.svn.wordpress.org/trunk@61379 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ea60bd5 commit d5cbd3d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/js/_enqueues/lib/auth-check.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,23 @@
159159
setShowTimeout();
160160
});
161161
}).on( 'heartbeat-tick.wp-auth-check', function( e, data ) {
162-
if ( 'wp-auth-check' in data ) {
162+
if ( ! ( 'wp-auth-check' in data ) ) {
163+
return;
164+
}
165+
166+
var showOrHide = function () {
163167
if ( ! data['wp-auth-check'] && wrap.hasClass( 'hidden' ) && ! tempHidden ) {
164168
show();
165169
} else if ( data['wp-auth-check'] && ! wrap.hasClass( 'hidden' ) ) {
166170
hide();
167171
}
172+
};
173+
174+
// This is necessary due to a race condition where the heartbeat-tick event may fire before DOMContentLoaded.
175+
if ( wrap ) {
176+
showOrHide();
177+
} else {
178+
$( showOrHide );
168179
}
169180
});
170181

0 commit comments

Comments
 (0)