From c692a1850b49f333fd87de76b7b6e1af4e5afd1e Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sun, 20 Jun 2021 09:48:44 -0700 Subject: [PATCH] fix: work around missing indexedDB.databases (#2054) --- src/client.js | 2 +- src/routes/_utils/idbReady.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/routes/_utils/idbReady.js diff --git a/src/client.js b/src/client.js index 2383e638..1a9b83df 100644 --- a/src/client.js +++ b/src/client.js @@ -6,7 +6,7 @@ import './routes/_utils/forceOnline' import { mark, stop } from './routes/_utils/marks' import { loadPolyfills } from './routes/_utils/polyfills/loadPolyfills' import { loadNonCriticalPolyfills } from './routes/_utils/polyfills/loadNonCriticalPolyfills' -import idbReady from 'safari-14-idb-fix' +import { idbReady } from './routes/_utils/idbReady' Promise.all([idbReady(), loadPolyfills()]).then(() => { mark('sapperStart') diff --git a/src/routes/_utils/idbReady.js b/src/routes/_utils/idbReady.js new file mode 100644 index 00000000..091d466a --- /dev/null +++ b/src/routes/_utils/idbReady.js @@ -0,0 +1,14 @@ +import safariIdbReady from 'safari-14-idb-fix' +import { isWebKit } from './userAgent/isWebKit' + +// workaround for a safari 14 bug, see https://github.com/jakearchibald/safari-14-idb-fix +export async function idbReady () { + if (!isWebKit()) { + return + } + if (typeof indexedDB === 'undefined' || !indexedDB.databases) { + // fix for https://github.com/jakearchibald/safari-14-idb-fix/pull/2 + return + } + await safariIdbReady() +}