Skip to content

Commit 9f7bcbc

Browse files
committed
PWA updater
1 parent 317245a commit 9f7bcbc

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

client/src/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@ ReactDOM.render(
1919
// If you want your app to work offline and load faster, you can change
2020
// unregister() to register() below. Note this comes with some pitfalls.
2121
// Learn more about service workers: https://cra.link/PWA
22-
serviceWorkerRegistration.register();
22+
serviceWorkerRegistration.register({
23+
onUpdate: updater
24+
});
25+
26+
function updater(registration) {
27+
alert('New version available! Ready to update?');
28+
if (registration && registration.waiting) {
29+
registration.waiting.postMessage({ type: 'SKIP_WAITING' });
30+
}
31+
window.location.reload();
32+
}
2333

2434
// If you want to start measuring performance in your app, pass a function
2535
// to log results (for example: reportWebVitals(console.log))

0 commit comments

Comments
 (0)