about summary refs log tree commit diff
path: root/app/javascript/mastodon/main.js
diff options
context:
space:
mode:
authorYamagishi Kazutoshi <ykzts@desire.sh>2022-11-11 09:33:59 +0900
committerGitHub <noreply@github.com>2022-11-11 01:33:59 +0100
commit53d26cfc1cc2779f699f3d3d56696484faefe87c (patch)
treee5ab0c6fa2f837f110ff2bebf32bd4990f50edd3 /app/javascript/mastodon/main.js
parent19a8563905cf613bb24e10e4e19bdbc1d0ff3b8a (diff)
Delay workbox import (#20376)
Diffstat (limited to 'app/javascript/mastodon/main.js')
-rw-r--r--app/javascript/mastodon/main.js27
1 files changed, 12 insertions, 15 deletions
diff --git a/app/javascript/mastodon/main.js b/app/javascript/mastodon/main.js
index f882217fb..69a7ee91f 100644
--- a/app/javascript/mastodon/main.js
+++ b/app/javascript/mastodon/main.js
@@ -2,6 +2,7 @@ import React from 'react';
 import ReactDOM from 'react-dom';
 import { setupBrowserNotifications } from 'mastodon/actions/notifications';
 import Mastodon, { store } from 'mastodon/containers/mastodon';
+import { me } from 'mastodon/initial_state';
 import ready from 'mastodon/ready';
 
 const perf = require('mastodon/performance');
@@ -19,23 +20,19 @@ function main() {
     ReactDOM.render(<Mastodon {...props} />, mountNode);
     store.dispatch(setupBrowserNotifications());
 
-    if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
-      const [{ Workbox }, { me }] = await Promise.all([
-        import('workbox-window'),
-        import('mastodon/initial_state'),
-      ]);
+    if (process.env.NODE_ENV === 'production' && me && 'serviceWorker' in navigator) {
+      const { Workbox } = await import('workbox-window');
+      const wb = new Workbox('/sw.js');
+      /** @type {ServiceWorkerRegistration} */
+      let registration;
 
-      if (me) {
-        const wb = new Workbox('/sw.js');
-
-        try {
-          await wb.register();
-        } catch (err) {
-          console.error(err);
-
-          return;
-        }
+      try {
+        registration = await wb.register();
+      } catch (err) {
+        console.error(err);
+      }
 
+      if (registration) {
         const registerPushNotifications = await import('mastodon/actions/push_notifications');
 
         store.dispatch(registerPushNotifications.register());