From 4e87fdcdfef860a303042e7806e110a0de84b195 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 24 Feb 2021 13:40:22 +0000 Subject: [PATCH] Fix object diffing when objects have different keys The object diff optimisation in 32cca0534c5ff7c7a86d854e6a00a4764652d20b is not correct for the case where `b` has some keys that are not in `a`. By ensuring their key arrays are same length, we can preserve optimisation and be correct as well. Fixes https://github.com/vector-im/element-web/issues/16514 --- src/utils/objects.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/objects.ts b/src/utils/objects.ts index 166c31c4c3..e7f4f0f907 100644 --- a/src/utils/objects.ts +++ b/src/utils/objects.ts @@ -89,6 +89,7 @@ export function objectHasDiff(a: O, b: O): boolean { if (a === b) return false; const aKeys = Object.keys(a); const bKeys = Object.keys(b); + if (aKeys.length !== bKeys.length) return true; const possibleChanges = arrayUnion(aKeys, bKeys); // if the amalgamation of both sets of keys has the a different length to the inputs then there must be a change if (possibleChanges.length !== aKeys.length) return true;