Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
fix(sw): update exp 29
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao authored May 15, 2022
1 parent 7125bc6 commit 0028043
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/components/root/WithServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,33 @@ export default class WithServiceWorker extends Component {

registration.addEventListener('updatefound', () => {
const installingWorker = registration.installing;
installingWorker.onstatechange = () => {
console.log(installingWorker)
if (installingWorker.state === 'installed') {
console.log(navigator.serviceWorker);
if (navigator.serviceWorker.controller) {
onUpdated && onUpdated();

if (installingWorker) {
installingWorker.onstatechange = () => {
console.log(installingWorker)
if (installingWorker.state === 'installed') {
console.log(navigator.serviceWorker);
if (navigator.serviceWorker.controller) {
onUpdated && onUpdated();
}
onInstalled && onInstalled();
}
onInstalled && onInstalled();
}
};
};
}

const waitingWorker = registration.waiting;
waitingWorker.onstatechange = () => {
console.log(waitingWorker)
if (waitingWorker.state === 'installed') {
console.log(navigator.serviceWorker);
if (navigator.serviceWorker.controller) {
onUpdated && onUpdated();
if (waitingWorker) {
waitingWorker.onstatechange = () => {
console.log(waitingWorker)
if (waitingWorker.state === 'installed') {
console.log(navigator.serviceWorker);
if (navigator.serviceWorker.controller) {
onUpdated && onUpdated();
}
onInstalled && onInstalled();
}
onInstalled && onInstalled();
}
};
};
}
});
} catch (err) {
console.error('Error during service worker registration:', err);
Expand Down

0 comments on commit 0028043

Please sign in to comment.