This commit is contained in:
Raluca Stan 2021-07-12 14:58:10 +03:00 committed by GitHub
parent ce965a3578
commit 4907ddcd5d
1 changed files with 22 additions and 12 deletions

View File

@ -47,6 +47,8 @@ const withReviews = ( OriginalComponent ) => {
delayedAppendReviews = this.props.delayFunction( this.appendReviews );
isMounted = false;
state = {
error: null,
loading: true,
@ -57,6 +59,7 @@ const withReviews = ( OriginalComponent ) => {
};
componentDidMount() {
this.isMounted = true;
this.replaceReviews();
}
@ -80,7 +83,9 @@ const withReviews = ( OriginalComponent ) => {
);
}
componentWillUnMount() {
componentWillUnmount() {
this.isMounted = false;
if ( this.delayedAppendReviews.cancel ) {
this.delayedAppendReviews.cancel();
}
@ -120,7 +125,6 @@ const withReviews = ( OriginalComponent ) => {
}
const { onReviewsReplaced } = this.props;
this.updateListOfReviews().then( onReviewsReplaced );
}
@ -158,16 +162,19 @@ const withReviews = ( OriginalComponent ) => {
reviews: newReviews,
totalReviews: newTotalReviews,
} ) => {
this.setState( {
reviews: oldReviews
.filter(
( review ) => Object.keys( review ).length
)
.concat( newReviews ),
totalReviews: newTotalReviews,
loading: false,
error: null,
} );
if ( this.isMounted ) {
this.setState( {
reviews: oldReviews
.filter(
( review ) =>
Object.keys( review ).length
)
.concat( newReviews ),
totalReviews: newTotalReviews,
loading: false,
error: null,
} );
}
return { newReviews };
}
@ -176,6 +183,9 @@ const withReviews = ( OriginalComponent ) => {
}
setError = async ( e ) => {
if ( ! this.isMounted ) {
return;
}
const { onReviewsLoadError } = this.props;
const error = await formatError( e );