Replace flawed objectHasValueChange usage with objectHasDiff

Fixes https://github.com/vector-im/riot-web/issues/14782

We need to check if the keys changed, not just the values.
This commit is contained in:
Travis Ralston 2020-07-30 14:08:18 -06:00
parent e810a31fe3
commit e953bfbf88
2 changed files with 3 additions and 17 deletions

View file

@ -47,7 +47,7 @@ import { polyfillTouchEvent } from "../../../@types/polyfill";
import { RoomNotificationStateStore } from "../../../stores/notifications/RoomNotificationStateStore";
import RoomListLayoutStore from "../../../stores/room-list/RoomListLayoutStore";
import { arrayHasOrderChange } from "../../../utils/arrays";
import { objectExcluding, objectHasValueChange } from "../../../utils/objects";
import { objectExcluding, objectHasDiff } from "../../../utils/objects";
import TemporaryTile from "./TemporaryTile";
import { ListNotificationState } from "../../../stores/notifications/ListNotificationState";
@ -181,7 +181,7 @@ export default class RoomSublist extends React.Component<IProps, IState> {
}
public shouldComponentUpdate(nextProps: Readonly<IProps>, nextState: Readonly<IState>): boolean {
if (objectHasValueChange(this.props, nextProps)) {
if (objectHasDiff(this.props, nextProps)) {
// Something we don't care to optimize has updated, so update.
return true;
}
@ -189,7 +189,7 @@ export default class RoomSublist extends React.Component<IProps, IState> {
// Do the same check used on props for state, without the rooms we're going to no-op
const prevStateNoRooms = objectExcluding(this.state, ['rooms']);
const nextStateNoRooms = objectExcluding(nextState, ['rooms']);
if (objectHasValueChange(prevStateNoRooms, nextStateNoRooms)) {
if (objectHasDiff(prevStateNoRooms, nextStateNoRooms)) {
return true;
}

View file

@ -58,20 +58,6 @@ export function objectShallowClone(a: any, propertyCloner?: (k: string, v: any)
return newObj;
}
/**
* Determines if the two objects, which are assumed to be of the same
* key shape, have a difference in their values. If a difference is
* determined, true is returned.
* @param a The first object. Must be defined.
* @param b The second object. Must be defined.
* @returns True if there's a perceptual difference in the object's values.
*/
export function objectHasValueChange(a: any, b: any): boolean {
const aValues = Object.values(a);
const bValues = Object.values(b);
return arrayHasDiff(aValues, bValues);
}
/**
* Determines if any keys were added, removed, or changed between two objects.
* For changes, simple triple equal comparisons are done, not in-depth