Skip to content

Commit 7f4ae1f

Browse files
author
Josh Crowther
authored
IE11 "Can't redefine non-configurable property 'length'" Error (#772)
* Fix IE11 property override issue * [AUTOMATED]: Prettier Code Styling
1 parent 7764746 commit 7f4ae1f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

packages/firestore/src/api/database.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,9 +1901,17 @@ function throwDocChangesMethodError(): never {
19011901
);
19021902
}
19031903

1904-
Object.defineProperty(QuerySnapshot.prototype.docChanges, 'length', {
1905-
get: () => throwDocChangesMethodError()
1906-
});
1904+
/**
1905+
* This is technically overwriting the `Function.prototype.length` property of
1906+
* `docChanges`. On IE11, the property is improperly defined with
1907+
* `{ configurable: false }` which causes this line to throw. Wrap in a
1908+
* try-catch to ensure that we still have a functional SDK.
1909+
*/
1910+
try {
1911+
Object.defineProperty(QuerySnapshot.prototype.docChanges, 'length', {
1912+
get: () => throwDocChangesMethodError()
1913+
});
1914+
} catch (err) {} // Ignore this failure intentionally
19071915

19081916
if (typeof Symbol !== 'undefined') {
19091917
Object.defineProperty(QuerySnapshot.prototype.docChanges, Symbol.iterator, {

0 commit comments

Comments
 (0)