Skip to content

Commit

Permalink
Deal with the component unmounting while a fetch is ongoing
Browse files Browse the repository at this point in the history
  • Loading branch information
notnownikki committed Jun 1, 2017
1 parent 42172c0 commit ea6ff87
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions blocks/library/embed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ registerBlock( 'core/embed', {
}
}

componentWillUnmount() {
// can't about the fetch promise, so let it know we will unmount
this.unmounting = true;
}

doServerSideRender( event ) {
if ( event ) {
event.preventDefault();
Expand All @@ -103,6 +108,9 @@ registerBlock( 'core/embed', {
credentials: 'include',
} ).then(
( response ) => {
if ( this.unmounting ) {
return;
}
response.json().then( ( obj ) => {
const { html, type } = obj;
if ( html ) {
Expand Down

0 comments on commit ea6ff87

Please sign in to comment.