@@ -108,6 +108,8 @@ export function isPropPresent(obj: Record<string, unknown>, prop: string) {
108108 * Compares if two values are the same borrowed from:
109109 * https://github.com/epoberezkin/fast-deep-equal
110110 * We added a case for file matching since `Object.keys` doesn't work with Files.
111+ *
112+ * NB: keys with the value undefined are ignored in the evaluation and considered equal to missing keys.
111113 * */
112114export function isEqual ( a : any , b : any ) {
113115 if ( a === b ) return true ;
@@ -162,7 +164,13 @@ export function isEqual(a: any, b: any) {
162164 if ( a . toString !== Object . prototype . toString ) return a . toString ( ) === b . toString ( ) ;
163165
164166 keys = Object . keys ( a ) ;
165- length = keys . length ;
167+ length = keys . length - countUndefinedValues ( a , keys ) ;
168+
169+ if ( length !== Object . keys ( b ) . length - countUndefinedValues ( b , Object . keys ( b ) ) ) return false ;
170+
171+ for ( i = length ; i -- !== 0 ; ) {
172+ if ( ! Object . prototype . hasOwnProperty . call ( b , keys [ i ] ) ) return false ;
173+ }
166174
167175 for ( i = length ; i -- !== 0 ; ) {
168176 // eslint-disable-next-line no-var
@@ -179,6 +187,17 @@ export function isEqual(a: any, b: any) {
179187 return a !== a && b !== b ;
180188}
181189
190+ function countUndefinedValues ( a : any , keys : string [ ] ) {
191+ let result = 0 ;
192+ for ( let i = keys . length ; i -- !== 0 ; ) {
193+ // eslint-disable-next-line no-var
194+ var key = keys [ i ] ;
195+
196+ if ( a [ key ] === undefined ) result ++ ;
197+ }
198+ return result ;
199+ }
200+
182201export function isFile ( a : unknown ) : a is File {
183202 if ( ! isClient ) {
184203 return false ;
0 commit comments