1010// To learn more about the benefits of this model and instructions on how to
1111// opt-in, read https://cra.link/PWA
1212
13+ import { toast } from "react-toastify" ;
14+
1315const isLocalhost = Boolean (
1416 window . location . hostname === 'localhost' ||
1517 // [::1] is the IPv6 localhost address.
@@ -48,6 +50,10 @@ export function register(config?: Config) {
4850 'PWA: This web app is being served cache-first by a service ' +
4951 'worker. To learn more, visit https://cra.link/PWA'
5052 ) ;
53+
54+ toast . info ( "PWA is available!" , {
55+ position : toast . POSITION . BOTTOM_LEFT
56+ } ) ;
5157 } ) ;
5258 } else {
5359 // Is not localhost. Just register service worker
@@ -76,6 +82,15 @@ function registerValidSW(swUrl: string, config?: Config) {
7682 'PWA: New content is available and will be used when all '
7783 ) ;
7884
85+ // registration?.waiting?.postMessage({ type: 'SKIP_WAITING' });
86+ toast . info ( "New content is available! Auto-updating..." , {
87+ position : toast . POSITION . BOTTOM_LEFT ,
88+ autoClose : false
89+ } ) ;
90+
91+ registration . waiting ?. postMessage ( { type : 'SKIP_WAITING' } ) ;
92+ registration . update ( ) ;
93+
7994 // Execute callback
8095 if ( config && config . onUpdate ) {
8196 config . onUpdate ( registration ) ;
@@ -86,6 +101,10 @@ function registerValidSW(swUrl: string, config?: Config) {
86101 // "Content is cached for offline use." message.
87102 console . log ( 'PWA: Content is cached for offline use.' ) ;
88103
104+ toast . info ( "PWA is available!" , {
105+ position : toast . POSITION . BOTTOM_LEFT ,
106+ } ) ;
107+
89108 // Execute callback
90109 if ( config && config . onSuccess ) {
91110 config . onSuccess ( registration ) ;
0 commit comments