From d635ca96f8c5dbdc993f30b1f3a3a0b4359e3e2e Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Tue, 23 Apr 2019 19:59:23 +0800 Subject: [PATCH] Avoid synchronous xhr by using window.sendBeacon when available (#14994) --- .../editor/src/components/post-locked-modal/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/editor/src/components/post-locked-modal/index.js b/packages/editor/src/components/post-locked-modal/index.js index b9c8de97f3d93e..8c6417ae403c82 100644 --- a/packages/editor/src/components/post-locked-modal/index.js +++ b/packages/editor/src/components/post-locked-modal/index.js @@ -121,9 +121,13 @@ class PostLockedModal extends Component { data.append( 'post_ID', postId ); data.append( 'active_post_lock', activePostLock ); - const xhr = new window.XMLHttpRequest(); - xhr.open( 'POST', postLockUtils.ajaxUrl, false ); - xhr.send( data ); + if ( window.navigator.sendBeacon ) { + window.navigator.sendBeacon( postLockUtils.ajaxUrl, data ); + } else { + const xhr = new window.XMLHttpRequest(); + xhr.open( 'POST', postLockUtils.ajaxUrl, false ); + xhr.send( data ); + } } render() {