Skip to content

Commit 353f5ca

Browse files
authored
Fix IE11 broken by Crypto change. (#2832)
* Fix IE11 broken by Crypto change. * Suppress Lint. * Rearrangement.
1 parent 74b06f5 commit 353f5ca

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/firestore/src/platform_browser/browser_platform.ts

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ import { NoopConnectivityMonitor } from '../remote/connectivity_monitor_noop';
2525
import { BrowserConnectivityMonitor } from './browser_connectivity_monitor';
2626
import { WebChannelConnection } from './webchannel_connection';
2727

28+
// Polyfill for IE
29+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
30+
const crypto = window.crypto || (window as any).msCrypto;
31+
2832
export class BrowserPlatform implements Platform {
2933
readonly useProto3Json = true;
3034
readonly base64Available: boolean;

packages/firestore/src/util/misc.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ export class AutoId {
3131
let autoId = '';
3232
while (autoId.length < 20) {
3333
const bytes = PlatformSupport.getPlatform().randomBytes(40);
34-
bytes.forEach(b => {
34+
for (const b of Array.from(bytes)) {
3535
// Length of `chars` is 62. We only take bytes between 0 and 62*4-1
3636
// (both inclusive). The value is then evenly mapped to indices of `char`
3737
// via a modulo operation.
3838
const maxValue = 62 * 4 - 1;
3939
if (autoId.length < 20 && b <= maxValue) {
4040
autoId += chars.charAt(b % 62);
4141
}
42-
});
42+
}
4343
}
4444
assert(autoId.length === 20, 'Invalid auto ID: ' + autoId);
4545
return autoId;

0 commit comments

Comments
 (0)