From 7e50464eeb07a0a7857a346a400a75a2322b7f39 Mon Sep 17 00:00:00 2001
From: Travis Ralston <travpc@gmail.com>
Date: Thu, 23 Jul 2020 22:19:16 -0600
Subject: [PATCH] Fix filtering causing sticky header artifacts

In 7b97c3032b8c25874c8bbe9d71e64a379b20a46e we reduced the RoomList updates to just added/removed sublists, but didn't consider that we might also have to handle lengths of those sublists changing enough for us to fix the sticky headers.
---
 src/components/views/rooms/RoomList.tsx | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/components/views/rooms/RoomList.tsx b/src/components/views/rooms/RoomList.tsx
index 8d1879418a..ef331fe1f5 100644
--- a/src/components/views/rooms/RoomList.tsx
+++ b/src/components/views/rooms/RoomList.tsx
@@ -239,7 +239,22 @@ export default class RoomList extends React.Component<IProps, IState> {
         const previousListIds = Object.keys(this.state.sublists);
         const newListIds = Object.keys(newLists);
 
-        if (arrayHasDiff(previousListIds, newListIds)) {
+        let doUpdate = arrayHasDiff(previousListIds, newListIds);
+        if (!doUpdate) {
+            // so we didn't have the visible sublists change, but did the contents of those
+            // sublists change significantly enough to break the sticky headers? Probably, so
+            // let's check the length of each.
+            for (const tagId of newListIds) {
+                const oldRooms = this.state.sublists[tagId];
+                const newRooms = newLists[tagId];
+                if (oldRooms.length !== newRooms.length) {
+                    doUpdate = true;
+                    break;
+                }
+            }
+        }
+
+        if (doUpdate) {
             this.setState({sublists: newLists}, () => {
                 this.props.onResize();
             });