From 223bd40703871b3bac0a4589274db377cf92060b Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Tue, 24 Apr 2018 15:01:24 -0300 Subject: [PATCH] Fix post with layout to not create new post components (#1611) --- app/components/post_list/with_layout.js | 23 ++++++++----------- .../profile_picture/profile_picture.js | 15 +++++++++--- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/app/components/post_list/with_layout.js b/app/components/post_list/with_layout.js index 570856a45..fd4774685 100644 --- a/app/components/post_list/with_layout.js +++ b/app/components/post_list/with_layout.js @@ -17,25 +17,22 @@ function withLayout(WrappedComponent) { static defaultProps = { onLayoutCalled: emptyFunction, - } + }; onLayout = (event) => { const {height} = event.nativeEvent.layout; - this.props.onLayoutCalled(this.props.index, height); + const {shouldCallOnLayout} = this.props; + if (shouldCallOnLayout) { + this.props.onLayoutCalled(this.props.index, height); + } }; render() { - const {index, onLayoutCalled, shouldCallOnLayout, ...otherProps} = this.props; //eslint-disable-line no-unused-vars - - if (shouldCallOnLayout) { - return ( - - - - ); - } - - return ; + return ( + + + + ); } }; } diff --git a/app/components/profile_picture/profile_picture.js b/app/components/profile_picture/profile_picture.js index 3c6f5adb5..a7b534721 100644 --- a/app/components/profile_picture/profile_picture.js +++ b/app/components/profile_picture/profile_picture.js @@ -49,6 +49,7 @@ export default class ProfilePicture extends PureComponent { componentWillMount() { const {edit, imageUri, user} = this.props; + this.mounted = true; if (edit && imageUri) { this.setImageURL(imageUri); @@ -65,18 +66,26 @@ export default class ProfilePicture extends PureComponent { componentWillUpdate(nextProps) { if (Boolean(nextProps.user) !== Boolean(this.props.user) || nextProps.user.id !== this.props.user.id) { - this.setState({pictureUrl: null}); - const nextUser = nextProps.user; + if (this.mounted) { + this.setState({pictureUrl: null}); + } + if (nextUser) { ImageCacheManager.cache('', Client4.getProfilePictureUrl(nextUser.id, nextUser.last_picture_update), this.setImageURL); } } } + componentWillUnmount() { + this.mounted = false; + } + setImageURL = (pictureUrl) => { - this.setState({pictureUrl}); + if (this.mounted) { + this.setState({pictureUrl}); + } }; render() {