Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Chrome: Avoid the mounted boolean and call the abort instead
  • Loading branch information
youknowriad committed May 25, 2017
commit 58945a17d668b2af9495b43fba64fe1b6061108e
13 changes: 6 additions & 7 deletions editor/sidebar/featured-image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ class FeaturedImage extends Component {
media: null,
loading: false,
};

// This boolean should be removed when we provide QueryComponents
this.mounted = true;
}

componentDidMount() {
Expand All @@ -43,7 +40,9 @@ class FeaturedImage extends Component {
}

componentWillUnmount() {
this.mounted = false;
if ( this.fetchMediaRequest ) {
this.fetchMediaRequest.abort();
}
}

fetchMedia() {
Expand All @@ -54,9 +53,9 @@ class FeaturedImage extends Component {
}
this.setState( { loading: true } );
const mediaIdToLoad = this.props.featuredImageId;
new wp.api.models.Media( { id: mediaIdToLoad } ).fetch()
this.fetchMediaRequest = new wp.api.models.Media( { id: mediaIdToLoad } ).fetch()
.done( ( media ) => {
if ( ! this.mounted || this.props.featuredImageId !== mediaIdToLoad ) {
if ( this.props.featuredImageId !== mediaIdToLoad ) {
return;
}
this.setState( {
Expand All @@ -65,7 +64,7 @@ class FeaturedImage extends Component {
} );
} )
.fail( () => {
if ( ! this.mounted || this.props.featuredImageId !== mediaIdToLoad ) {
if ( this.props.featuredImageId !== mediaIdToLoad ) {
return;
}
this.setState( {
Expand Down