Browse Source

fix reloadSW no trigger error

pull/3061/head
陈帅 7 years ago
parent
commit
6e65ecd52c
  1. 1
      .eslintignore
  2. 33
      src/global.js

1
.eslintignore

@ -1,2 +1,3 @@
/functions/mock/**
/scripts
/config

33
src/global.js

@ -9,18 +9,7 @@ window.addEventListener('sw.offline', () => {
// Pop up a prompt on the page asking the user if they want to use the latest version
window.addEventListener('sw.updated', e => {
const key = `open${Date.now()}`;
const btn = (
<Button type="primary" onClick={() => notification.close(key)}>
{formatMessage({ id: 'app.pwa.serviceworker.updated.ok' })}
</Button>
);
notification.open({
message: formatMessage({ id: 'app.pwa.serviceworker.updated' }),
description: formatMessage({ id: 'app.pwa.serviceworker.updated.hint' }),
btn,
key,
onClose: async () => {
const reloadSW = async () => {
// Check if there is sw whose state is waiting in ServiceWorkerRegistration
// https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration
const worker = e.detail && e.detail.waiting;
@ -42,6 +31,24 @@ window.addEventListener('sw.updated', e => {
// Refresh current page to use the updated HTML and other assets after SW has skiped waiting
window.location.reload(true);
return true;
},
};
const key = `open${Date.now()}`;
const btn = (
<Button
type="primary"
onClick={() => {
notification.close(key);
reloadSW();
}}
>
{formatMessage({ id: 'app.pwa.serviceworker.updated.ok' })}
</Button>
);
notification.open({
message: formatMessage({ id: 'app.pwa.serviceworker.updated' }),
description: formatMessage({ id: 'app.pwa.serviceworker.updated.hint' }),
btn,
key,
onClose: async () => {},
});
});

Loading…
Cancel
Save