From f26218618a5e32c82ff9d16ea8a58d2b4184fde3 Mon Sep 17 00:00:00 2001 From: korynunn Date: Mon, 19 Dec 2022 09:57:03 +1000 Subject: [PATCH 1/4] Use userAgent instead of depricated appVersion --- packages/firestore/src/local/indexeddb_persistence.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firestore/src/local/indexeddb_persistence.ts b/packages/firestore/src/local/indexeddb_persistence.ts index 9e1857dde83..866b3f2accf 100644 --- a/packages/firestore/src/local/indexeddb_persistence.ts +++ b/packages/firestore/src/local/indexeddb_persistence.ts @@ -977,7 +977,7 @@ export class IndexedDbPersistence implements Persistence { // to make sure it gets a chance to run. this.markClientZombied(); - if (isSafari() && navigator.appVersion.match(/Version\/1[45]/)) { + if (isSafari() && navigator.userAgent.match(/Version\/1[45]/)) { // On Safari 14 and 15, we do not run any cleanup actions as it might // trigger a bug that prevents Safari from re-opening IndexedDB during // the next page load. From f394a1dd4c3364939b41837b48fa52101a220751 Mon Sep 17 00:00:00 2001 From: korynunn Date: Mon, 6 Mar 2023 07:52:44 +1000 Subject: [PATCH 2/4] Updated check to include appVersion and userAgent, include version 16, and include regex for WKWebView string --- packages/firestore/src/local/indexeddb_persistence.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/firestore/src/local/indexeddb_persistence.ts b/packages/firestore/src/local/indexeddb_persistence.ts index 866b3f2accf..bdf66193344 100644 --- a/packages/firestore/src/local/indexeddb_persistence.ts +++ b/packages/firestore/src/local/indexeddb_persistence.ts @@ -977,8 +977,8 @@ export class IndexedDbPersistence implements Persistence { // to make sure it gets a chance to run. this.markClientZombied(); - if (isSafari() && navigator.userAgent.match(/Version\/1[45]/)) { - // On Safari 14 and 15, we do not run any cleanup actions as it might + if (isSafari() && (navigator.appVersion.match(/(?:Version|Mobile)\/1[456]/) || navigator.userAgent.match(/(?:Version|Mobile)\/1[456]/))) { + // On Safari 14, 15, and 16, we do not run any cleanup actions as it might // trigger a bug that prevents Safari from re-opening IndexedDB during // the next page load. // See https://bugs.webkit.org/show_bug.cgi?id=226547 From ebd302f22ccb5aab4f3f7b241775d4a9abfca3ea Mon Sep 17 00:00:00 2001 From: korynunn Date: Mon, 6 Mar 2023 08:03:30 +1000 Subject: [PATCH 3/4] Changeset --- .changeset/chilled-buckets-sneeze.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/chilled-buckets-sneeze.md diff --git a/.changeset/chilled-buckets-sneeze.md b/.changeset/chilled-buckets-sneeze.md new file mode 100644 index 00000000000..c0b61bfc8dc --- /dev/null +++ b/.changeset/chilled-buckets-sneeze.md @@ -0,0 +1,6 @@ +--- +'@firebase/firestore': patch +'firebase': patch +--- + +Check navigator.userAgent, in addition to navigator.appVersion, when determining whether to work around an IndexedDb bug in Safari. Add check for Mobile/# in addition to Version/# to include WKWebView safari versions in this check. From 85a82ee21361a39fb0ab5e17f651007294e8866b Mon Sep 17 00:00:00 2001 From: korynunn Date: Mon, 6 Mar 2023 10:16:58 +1000 Subject: [PATCH 4/4] Reduce changeset description size, linting, regex to varaible --- .changeset/chilled-buckets-sneeze.md | 2 +- packages/firestore/src/local/indexeddb_persistence.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.changeset/chilled-buckets-sneeze.md b/.changeset/chilled-buckets-sneeze.md index c0b61bfc8dc..d485e384f70 100644 --- a/.changeset/chilled-buckets-sneeze.md +++ b/.changeset/chilled-buckets-sneeze.md @@ -3,4 +3,4 @@ 'firebase': patch --- -Check navigator.userAgent, in addition to navigator.appVersion, when determining whether to work around an IndexedDb bug in Safari. Add check for Mobile/# in addition to Version/# to include WKWebView safari versions in this check. +Check navigator.userAgent, in addition to navigator.appVersion, when determining whether to work around an IndexedDb bug in Safari. diff --git a/packages/firestore/src/local/indexeddb_persistence.ts b/packages/firestore/src/local/indexeddb_persistence.ts index bdf66193344..a4f70458df3 100644 --- a/packages/firestore/src/local/indexeddb_persistence.ts +++ b/packages/firestore/src/local/indexeddb_persistence.ts @@ -977,7 +977,12 @@ export class IndexedDbPersistence implements Persistence { // to make sure it gets a chance to run. this.markClientZombied(); - if (isSafari() && (navigator.appVersion.match(/(?:Version|Mobile)\/1[456]/) || navigator.userAgent.match(/(?:Version|Mobile)\/1[456]/))) { + const safariIndexdbBugVersionRegex = /(?:Version|Mobile)\/1[456]/; + if ( + isSafari() && + (navigator.appVersion.match(safariIndexdbBugVersionRegex) || + navigator.userAgent.match(safariIndexdbBugVersionRegex)) + ) { // On Safari 14, 15, and 16, we do not run any cleanup actions as it might // trigger a bug that prevents Safari from re-opening IndexedDB during // the next page load.