3cfba323f6
* perf(room list): clear room list item vm only when changing space Clearing all the item vms at every room list change is causing massive re-render of all the room list items. References to the vms are already removed when out of view (see RoomListViewMode.updateVisibleRooms) and handled by GC. * perf(room list): avoid to re-render filters at every room list update RoomListView re-renders on update but the filters (children) don't need to. Add a memo to avoid excessive-rerenders. * chore: add `keepIfSame` to do diff on vm objects * perf(room list): avoid to create new filter ids and keys when the room list is updated The filterKeys are passed in the virtuoso context so it should reduce internal computing The filter ids array has always the same value, there is no point to create a new instance. * test(room list): remove no longer relevant test * test(room list): add new test to ensure that room list item vms are preserved
21 lines
748 B
TypeScript
21 lines
748 B
TypeScript
/*
|
|
* Copyright 2026 Element Creations Ltd.
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
* Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
import { isEqual } from "lodash";
|
|
|
|
/**
|
|
* Returns the current value if it is deeply equal to the next value, otherwise returns the next value.
|
|
* This is useful to prevent unnecessary re-renders in React components when the value has not changed.
|
|
* @param current The current value
|
|
* @param next The next value
|
|
* @returns The current value if it is deeply equal to the next value, otherwise the next value
|
|
*/
|
|
export function keepIfSame<T>(current: T, next: T): T {
|
|
if (isEqual(current, next)) return current;
|
|
return next;
|
|
}
|