Skip to content

Commit 53f3564

Browse files
committed
fix(router): type cast correctly for IE 11 bug breaking URL Unification when comparing objects (#30464)
PR #30393 corrected behavior where Object.keys sometimes returns an `undefined` value. However, the types didn't reflect this in the code. That fix actually missed one value that could return `undefined`. This PR corrects this by casting the types to what they can be in IE 11. This ensures the code behaves as it should when this edge case comes up. PR Close #30464
1 parent d20b0f4 commit 53f3564

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎packages/router/src/utils/collection.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ export function shallowEqualArrays(a: any[], b: any[]): boolean {
2121
}
2222

2323
export function shallowEqual(a: {[x: string]: any}, b: {[x: string]: any}): boolean {
24-
const k1 = Object.keys(a);
25-
const k2 = Object.keys(b);
26-
// IE 11 sometimes returns an `undefined` value here. This guard is for IE 11 only.
27-
if (!(k1 || k2) || k1.length != k2.length) {
24+
// Casting Object.keys return values to include `undefined` as there are some cases
25+
// in IE 11 where this can happen. Cannot provide a test because the behavior only
26+
// exists in certain circumstances in IE 11, therefore doing this cast ensures the
27+
// logic is correct for when this edge case is hit.
28+
const k1 = Object.keys(a) as string[] | undefined;
29+
const k2 = Object.keys(b) as string[] | undefined;
30+
if (!k1 || !k2 || k1.length != k2.length) {
2831
return false;
2932
}
3033
let key: string;

0 commit comments

Comments
 (0)