Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ function registerValidSW(swUrl: string, config?: Config) {
}
};
};

// in the case a page is loaded an a service worker is already waiting
// we should trigger the onUpdate callback
const waitingWorker = registration.waiting;
if (waitingWorker) {
if (navigator.serviceWorker.controller && waitingWorker.state === 'installed') {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://cra.link/PWA.'
);

// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
}
}
}
})
.catch((error) => {
console.error('Error during service worker registration:', error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,26 @@ function registerValidSW(swUrl, config) {
}
};
};

// in the case a page is loaded an a service worker is already waiting
// we should trigger the onUpdate callback
const waitingWorker = registration.waiting;
if (waitingWorker) {
if (navigator.serviceWorker.controller && waitingWorker.state === 'installed') {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://cra.link/PWA.'
);

// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
}
}
}
})
.catch((error) => {
console.error('Error during service worker registration:', error);
Expand Down