Skip to content

Commit a7ae4de

Browse files
committed
Speculative fix for Firestore internal error.
When this hits, firestore fails for the rest of the lift of the page and the page appears semi functional. Better to force reload and have an actual working page even though it's not a great user experience. See firebase/firebase-js-sdk#1642 for details.
1 parent 2ebbe7d commit a7ae4de

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

static/main.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,19 @@ window.addEventListener('error', (e) => {
526526
e.error, JSON.stringify(e, ['body', 'error', 'message', 'stack']));
527527
});
528528

529+
const FIRESTORE_INTERNAL_ERROR =
530+
`INTERNAL ASSERTION FAILED: AsyncQueue is already failed: The transaction was aborted, so the request cannot be fulfilled`;
529531
const NETWORK_OFFLINE_ERROR_MESSAGE =
530532
'A network error occurred. Are you offline?';
531533
const FETCH_ERROR_MESSAGE =
532534
'A network error occurred, and the request could not be completed.';
533535

536+
// See https://github.com/firebase/firebase-js-sdk/issues/1642.
537+
function reloadOnFirestoreInternalError(message: string) {
538+
if (message.includes(FIRESTORE_INTERNAL_ERROR))
539+
window.location.reload();
540+
}
541+
534542
// Different promise types stow a human understandable message in different
535543
// places. :( Also, if we catch via a try/catch, then we need to pass the
536544
// exception itself as an argument this function instead of e.reason.
@@ -547,6 +555,7 @@ function getErrorMessage(reason: any) {
547555
if (error && error.code === -1 && message === FETCH_ERROR_MESSAGE)
548556
message = NETWORK_OFFLINE_ERROR_MESSAGE;
549557

558+
reloadOnFirestoreInternalError(message);
550559
return message;
551560
}
552561

@@ -563,6 +572,8 @@ window.addEventListener('unhandledrejection', (e) => {
563572
reason, ['stack', 'message', 'body', 'result', 'error', 'code']);
564573

565574
let message = getErrorMessage(e.reason);
575+
reloadOnFirestoreInternalError(message);
576+
566577
if (message)
567578
ErrorLogger.log(message, details);
568579
else

0 commit comments

Comments
 (0)