From 98e7a56822f93d92e87b49a3172bacc3adfc0e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Fri, 3 Sep 2021 20:41:09 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20repalce=20deprecated=20ap?= =?UTF-8?q?i=20:=20window.location.reload=20(#9040)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 fix: repalce deprecated api : window.location.reload * fix test --- src/global.tsx | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/global.tsx b/src/global.tsx index 108959db..29f47a09 100644 --- a/src/global.tsx +++ b/src/global.tsx @@ -5,6 +5,20 @@ import defaultSettings from '../config/defaultSettings'; const { pwa } = defaultSettings; const isHttps = document.location.protocol === 'https:'; +const clearCache = () => { + // remove all caches + if (window.caches) { + caches + .keys() + .then((keys) => { + keys.forEach((key) => { + caches.delete(key); + }); + }) + .catch((e) => console.log(e)); + } +}; + // if pwa is true if (pwa) { // Notify user if offline now @@ -34,8 +48,9 @@ if (pwa) { }; worker.postMessage({ type: 'skip-waiting' }, [channel.port2]); }); - // Refresh current page to use the updated HTML and other assets after SW has skiped waiting - window.location.reload(true); + + clearCache(); + window.location.reload(); return true; }; const key = `open${Date.now()}`; @@ -72,12 +87,5 @@ if (pwa) { if (sw) sw.unregister(); }); - // remove all caches - if (window.caches && window.caches.keys()) { - caches.keys().then((keys) => { - keys.forEach((key) => { - caches.delete(key); - }); - }); - } + clearCache(); }