From e0827be8c8aed0aaae298fca7bb15a00c8edcca6 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 19 Jun 2021 09:29:32 -0700 Subject: [PATCH] fix: fix safari 14 idb issue (#2053) --- package.json | 1 + src/client.js | 5 ++--- src/routes/_utils/polyfills/loadPolyfills.js | 7 +++++-- yarn.lock | 5 +++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 5adb53dd..6d56a45b 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,7 @@ "rollup-plugin-babel": "^4.4.0", "rollup-plugin-terser": "^7.0.2", "rtl-detect": "^1.0.3", + "safari-14-idb-fix": "^1.0.2", "sapper": "nolanlawson/sapper#for-pinafore-25", "sass": "^1.32.13", "stringz": "^2.1.0", diff --git a/src/client.js b/src/client.js index 2026e1fb..2383e638 100644 --- a/src/client.js +++ b/src/client.js @@ -6,10 +6,9 @@ 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' -mark('loadPolyfills') -loadPolyfills().then(() => { - stop('loadPolyfills') +Promise.all([idbReady(), loadPolyfills()]).then(() => { mark('sapperStart') sapper.start({ target: document.querySelector('#sapper') }) stop('sapperStart') diff --git a/src/routes/_utils/polyfills/loadPolyfills.js b/src/routes/_utils/polyfills/loadPolyfills.js index 28a8cb63..7f572d2e 100644 --- a/src/routes/_utils/polyfills/loadPolyfills.js +++ b/src/routes/_utils/polyfills/loadPolyfills.js @@ -3,6 +3,7 @@ import { importIntlLocale, importIntlPluralRules, importIntlRelativeTimeFormat, importRequestIdleCallback } from './asyncPolyfills' +import { mark, stop } from '../marks' async function loadIntlPolyfillsIfNecessary () { // Have to chain these so that they load in the proper order. @@ -20,9 +21,11 @@ async function loadIntlPolyfillsIfNecessary () { ]) } -export function loadPolyfills () { - return Promise.all([ +export async function loadPolyfills () { + mark('loadPolyfills') + await Promise.all([ typeof requestIdleCallback !== 'function' && importRequestIdleCallback(), loadIntlPolyfillsIfNecessary() ]) + stop('loadPolyfills') } diff --git a/yarn.lock b/yarn.lock index a8ed7e61..02e60ef9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5983,6 +5983,11 @@ rxjs@^6.6.7: dependencies: tslib "^1.9.0" +safari-14-idb-fix@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/safari-14-idb-fix/-/safari-14-idb-fix-1.0.2.tgz#c489feca93bc71628019ff490487370255316b86" + integrity sha512-RvZsa8kntL5qOnLdJbHfF7oAw596M/mRjpHXpASGu1/Rpn4SnI2IemHz3oUeK0chngZIcwyBXLSYBLrpIeE42A== + safe-buffer@5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1: version "5.1.2" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"