From 6aa96ef82f6fbe28321afa6cb64fe3cc12592ae6 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 31 Oct 2019 19:42:41 +0000 Subject: [PATCH] Fix bug where rooms would not appear when filtering We need to reset the scroll offset otherwise the component may be scrolled past the only content it has (Chrome just corrected the scroll offset but Firefox scrolled it anyway). NB. Introducing the new deriveStateFromProps method seems to means that react no longer calls componentWillMount so I've had to change it to componentDidMount (which it should have been anyway). Fixes https://github.com/vector-im/riot-web/issues/11263 --- src/components/structures/RoomSubList.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/structures/RoomSubList.js b/src/components/structures/RoomSubList.js index 0bb5c9e9be..921680b678 100644 --- a/src/components/structures/RoomSubList.js +++ b/src/components/structures/RoomSubList.js @@ -67,6 +67,9 @@ const RoomSubList = createReactClass({ // some values to get LazyRenderList starting scrollerHeight: 800, scrollTop: 0, + // React 16's getDerivedStateFromProps(props, state) doesn't give the previous props so + // we have to store the length of the list here so we can see if it's changed or not... + listLength: null, }; }, @@ -79,11 +82,20 @@ const RoomSubList = createReactClass({ }; }, - componentWillMount: function() { + componentDidMount: function() { this._headerButton = createRef(); this.dispatcherRef = dis.register(this.onAction); }, + statics: { + getDerivedStateFromProps: function(props, state) { + return { + listLength: props.list.length, + scrollTop: props.list.length === state.listLength ? state.scrollTop : 0, + }; + }, + }, + componentWillUnmount: function() { dis.unregister(this.dispatcherRef); },