about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>2018-05-15 02:58:11 +0900
committerEugen Rochko <eugen@zeonfederated.com>2018-05-14 19:58:11 +0200
commit03b69ebc450efc07246bd64204276941b7ede3fc (patch)
tree0f8fb7610a659d9245a4126d97fd18e97d09c01a /app
parented4bae182bd82ed424211bfb219ffa347058e8b2 (diff)
Disallow async function in service worker (#7482)
offline-plugin depends on webpack.optimize.UglifyJsPlugin, which is an
alias of uglifyjs-webpack-plugin v0.4.6. uglifyjs-webpack-plugin v0.4.6
uses uglify-js 2.8.29, which is not compatible with async function.
Diffstat (limited to 'app')
-rw-r--r--app/javascript/mastodon/service_worker/entry.js44
1 files changed, 23 insertions, 21 deletions
diff --git a/app/javascript/mastodon/service_worker/entry.js b/app/javascript/mastodon/service_worker/entry.js
index ba54ae996..5ad03caf2 100644
--- a/app/javascript/mastodon/service_worker/entry.js
+++ b/app/javascript/mastodon/service_worker/entry.js
@@ -28,11 +28,10 @@ self.addEventListener('fetch', function(event) {
     const asyncResponse = fetchRoot();
     const asyncCache = openWebCache();
 
-    event.respondWith(asyncResponse.then(async response => {
+    event.respondWith(asyncResponse.then(response => {
       if (response.ok) {
-        const cache = await asyncCache;
-        await cache.put('/', response);
-        return response.clone();
+        return asyncCache.then(cache => cache.put('/', response))
+                         .then(() => response.clone());
       }
 
       throw null;
@@ -41,35 +40,38 @@ self.addEventListener('fetch', function(event) {
     const asyncResponse = fetch(event.request);
     const asyncCache = openWebCache();
 
-    event.respondWith(asyncResponse.then(async response => {
+    event.respondWith(asyncResponse.then(response => {
       if (response.ok || response.type === 'opaqueredirect') {
-        await Promise.all([
+        return Promise.all([
           asyncCache.then(cache => cache.delete('/')),
           indexedDB.deleteDatabase('mastodon'),
-        ]);
+        ]).then(() => response);
       }
 
       return response;
     }));
   } else if (process.env.CDN_HOST ? url.host === process.env.CDN_HOST : url.pathname.startsWith('/system/')) {
-    event.respondWith(openSystemCache().then(async cache => {
-      const cached = await cache.match(event.request.url);
+    event.respondWith(openSystemCache().then(cache => {
+      return cache.match(event.request.url).then(cached => {
+        if (cached === undefined) {
+          return fetch(event.request).then(fetched => {
+            if (fetched.ok) {
+              const put = cache.put(event.request.url, fetched.clone());
 
-      if (cached === undefined) {
-        const fetched = await fetch(event.request);
+              put.catch(() => freeStorage());
 
-        if (fetched.ok) {
-          try {
-            await cache.put(event.request.url, fetched.clone());
-          } finally {
-            freeStorage();
-          }
-        }
+              return put.then(() => {
+                freeStorage();
+                return fetched;
+              });
+            }
 
-        return fetched;
-      }
+            return fetched;
+          });
+        }
 
-      return cached;
+        return cached;
+      });
     }));
   }
 });