Skip to content

Commit f490661

Browse files
Fix bug in AsyncQueue visibility handler
1 parent 41ed6f2 commit f490661

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

packages/firestore/src/util/async_queue.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { logDebug, logError } from './log';
2121
import { Deferred } from './promise';
2222
import { ExponentialBackoff } from '../remote/backoff';
2323
import { isIndexedDbTransactionError } from '../local/simple_db';
24-
import { getWindow } from '../platform/dom';
24+
import {getDocument} from '../platform/dom';
2525

2626
const LOG_TAG = 'AsyncQueue';
2727

@@ -235,12 +235,18 @@ export class AsyncQueue {
235235
// Visibility handler that triggers an immediate retry of all retryable
236236
// operations. Meant to speed up recovery when we regain file system access
237237
// after page comes into foreground.
238-
private visibilityHandler = (): void => this.backoff.skipBackoff();
238+
private visibilityHandler : () => void = () => {
239+
const document = getDocument();
240+
if (document) {
241+
logDebug(LOG_TAG, 'Visibility state changed to ', document.visibilityState);
242+
}
243+
this.backoff.skipBackoff();
244+
};
239245

240246
constructor() {
241-
const window = getWindow();
242-
if (window && typeof window.addEventListener === 'function') {
243-
window.addEventListener('visibilitychange', this.visibilityHandler);
247+
const document = getDocument();
248+
if (document && typeof document.addEventListener === 'function') {
249+
document.addEventListener('visibilitychange', this.visibilityHandler);
244250
}
245251
}
246252

@@ -293,9 +299,9 @@ export class AsyncQueue {
293299
this.verifyNotFailed();
294300
if (!this._isShuttingDown) {
295301
this._isShuttingDown = true;
296-
const window = getWindow();
297-
if (window) {
298-
window.removeEventListener('visibilitychange', this.visibilityHandler);
302+
const document = getDocument();
303+
if (document && typeof document.removeEventListener === 'function') {
304+
document.removeEventListener('visibilitychange', this.visibilityHandler);
299305
}
300306
await this.enqueueEvenAfterShutdown(op);
301307
}

0 commit comments

Comments
 (0)