Skip to content

Commit

Permalink
Avoid synchronous xhr by using window.sendBeacon when available (#14994)
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan authored and draganescu committed Apr 23, 2019
1 parent 39f9fec commit d635ca9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/editor/src/components/post-locked-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit d635ca9

Please sign in to comment.