diff --git a/routes/_database/databaseLifecycle.js b/routes/_database/databaseLifecycle.js index 4c75d1ca..011273dc 100644 --- a/routes/_database/databaseLifecycle.js +++ b/routes/_database/databaseLifecycle.js @@ -22,15 +22,12 @@ const DB_VERSION_INITIAL = 9 const DB_VERSION_SEARCH_ACCOUNTS = 10 const DB_VERSION_CURRENT = 10 -export function getDatabase (instanceName) { - if (!instanceName) { - throw new Error('instanceName is undefined in getDatabase()') - } - if (databaseCache[instanceName]) { - return Promise.resolve(databaseCache[instanceName]) - } +if (process.browser) { + require('indexeddb-getall-shim') // needed for Edge +} - databaseCache[instanceName] = new Promise((resolve, reject) => { +function createDatabase (instanceName) { + return new Promise((resolve, reject) => { let req = indexedDB.open(instanceName, DB_VERSION_CURRENT) openReqs[instanceName] = req req.onerror = reject @@ -87,9 +84,17 @@ export function getDatabase (instanceName) { } } req.onsuccess = () => resolve(req.result) - }).then(res => { - return addKnownInstance(instanceName).then(() => res) }) +} + +export async function getDatabase (instanceName) { + if (!instanceName) { + throw new Error('instanceName is undefined in getDatabase()') + } + if (!databaseCache[instanceName]) { + databaseCache[instanceName] = await createDatabase(instanceName) + await addKnownInstance(instanceName) + } return databaseCache[instanceName] } diff --git a/routes/_utils/asyncModules.js b/routes/_utils/asyncModules.js index 3cbed925..c3c5b67d 100644 --- a/routes/_utils/asyncModules.js +++ b/routes/_utils/asyncModules.js @@ -10,10 +10,6 @@ export const importRequestIdleCallback = () => import( /* webpackChunkName: 'requestidlecallback' */ 'requestidlecallback' ) -export const importIndexedDBGetAllShim = () => import( - /* webpackChunkName: 'indexeddb-getall-shim' */ 'indexeddb-getall-shim' - ) - export const importWebAnimationPolyfill = () => import( /* webpackChunkName: 'web-animations-js' */ 'web-animations-js' ) diff --git a/routes/_utils/loadPolyfills.js b/routes/_utils/loadPolyfills.js index 9642c9d6..7f5a037c 100644 --- a/routes/_utils/loadPolyfills.js +++ b/routes/_utils/loadPolyfills.js @@ -1,7 +1,6 @@ import { importIntersectionObserver, importRequestIdleCallback, - importIndexedDBGetAllShim, importWebAnimationPolyfill } from './asyncModules' @@ -9,7 +8,6 @@ export function loadPolyfills () { return Promise.all([ typeof IntersectionObserver === 'undefined' && importIntersectionObserver(), typeof requestIdleCallback === 'undefined' && importRequestIdleCallback(), - !IDBObjectStore.prototype.getAll && importIndexedDBGetAllShim(), !Element.prototype.animate && importWebAnimationPolyfill() ]) }