@@ -16,49 +16,49 @@ const isLocalhost = Boolean(
1616 window . location . hostname === '[::1]' ||
1717 // 127.0.0.1/8 is considered localhost for IPv4.
1818 window . location . hostname . match (
19- / ^ 1 2 7 (?: \. (?: 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | [ 0 1 ] ? [ 0 - 9 ] [ 0 - 9 ] ? ) ) { 3 } $ /
20- )
21- ) ;
19+ / ^ 1 2 7 (?: \. (?: 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | [ 0 1 ] ? [ 0 - 9 ] [ 0 - 9 ] ? ) ) { 3 } $ / ,
20+ ) ,
21+ )
2222
2323type Config = {
24- onSuccess ?: ( registration : ServiceWorkerRegistration ) => void ;
25- onUpdate ?: ( registration : ServiceWorkerRegistration ) => void ;
26- } ;
24+ onSuccess ?: ( registration : ServiceWorkerRegistration ) => void
25+ onUpdate ?: ( registration : ServiceWorkerRegistration ) => void
26+ }
2727
2828export function register ( config ?: Config ) {
2929 if ( process . env . NODE_ENV === 'production' && 'serviceWorker' in navigator ) {
3030 // The URL constructor is available in all browsers that support SW.
3131 const publicUrl = new URL (
3232 ( process as { env : { [ key : string ] : string } } ) . env . PUBLIC_URL ,
33- window . location . href
34- ) ;
33+ window . location . href ,
34+ )
3535 if ( publicUrl . origin !== window . location . origin ) {
3636 // Our service worker won't work if PUBLIC_URL is on a different origin
3737 // from what our page is served on. This might happen if a CDN is used to
3838 // serve assets; see https://github.com/facebook/create-react-app/issues/2374
39- return ;
39+ return
4040 }
4141
4242 window . addEventListener ( 'load' , ( ) => {
43- const swUrl = `${ process . env . PUBLIC_URL } /service-worker.js` ;
43+ const swUrl = `${ process . env . PUBLIC_URL } /service-worker.js`
4444
4545 if ( isLocalhost ) {
4646 // This is running on localhost. Let's check if a service worker still exists or not.
47- checkValidServiceWorker ( swUrl , config ) ;
47+ checkValidServiceWorker ( swUrl , config )
4848
4949 // Add some additional logging to localhost, pointing developers to the
5050 // service worker/PWA documentation.
5151 navigator . serviceWorker . ready . then ( ( ) => {
5252 console . log (
5353 'This web app is being served cache-first by a service ' +
54- 'worker. To learn more, visit https://bit.ly/CRA-PWA'
55- ) ;
56- } ) ;
54+ 'worker. To learn more, visit https://bit.ly/CRA-PWA' ,
55+ )
56+ } )
5757 } else {
5858 // Is not localhost. Just register service worker
59- registerValidSW ( swUrl , config ) ;
59+ registerValidSW ( swUrl , config )
6060 }
61- } ) ;
61+ } )
6262 }
6363}
6464
@@ -67,9 +67,9 @@ function registerValidSW(swUrl: string, config?: Config) {
6767 . register ( swUrl )
6868 . then ( registration => {
6969 registration . onupdatefound = ( ) => {
70- const installingWorker = registration . installing ;
70+ const installingWorker = registration . installing
7171 if ( installingWorker == null ) {
72- return ;
72+ return
7373 }
7474 installingWorker . onstatechange = ( ) => {
7575 if ( installingWorker . state === 'installed' ) {
@@ -79,65 +79,65 @@ function registerValidSW(swUrl: string, config?: Config) {
7979 // content until all client tabs are closed.
8080 console . log (
8181 'New content is available and will be used when all ' +
82- 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
83- ) ;
82+ 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' ,
83+ )
8484
8585 // Execute callback
8686 if ( config && config . onUpdate ) {
87- config . onUpdate ( registration ) ;
87+ config . onUpdate ( registration )
8888 }
8989 } else {
9090 // At this point, everything has been precached.
9191 // It's the perfect time to display a
9292 // "Content is cached for offline use." message.
93- console . log ( 'Content is cached for offline use.' ) ;
93+ console . log ( 'Content is cached for offline use.' )
9494
9595 // Execute callback
9696 if ( config && config . onSuccess ) {
97- config . onSuccess ( registration ) ;
97+ config . onSuccess ( registration )
9898 }
9999 }
100100 }
101- } ;
102- } ;
101+ }
102+ }
103103 } )
104104 . catch ( error => {
105- console . error ( 'Error during service worker registration:' , error ) ;
106- } ) ;
105+ console . error ( 'Error during service worker registration:' , error )
106+ } )
107107}
108108
109109function checkValidServiceWorker ( swUrl : string , config ?: Config ) {
110110 // Check if the service worker can be found. If it can't reload the page.
111111 fetch ( swUrl )
112112 . then ( response => {
113113 // Ensure service worker exists, and that we really are getting a JS file.
114- const contentType = response . headers . get ( 'content-type' ) ;
114+ const contentType = response . headers . get ( 'content-type' )
115115 if (
116116 response . status === 404 ||
117117 ( contentType != null && contentType . indexOf ( 'javascript' ) === - 1 )
118118 ) {
119119 // No service worker found. Probably a different app. Reload the page.
120120 navigator . serviceWorker . ready . then ( registration => {
121121 registration . unregister ( ) . then ( ( ) => {
122- window . location . reload ( ) ;
123- } ) ;
124- } ) ;
122+ window . location . reload ( )
123+ } )
124+ } )
125125 } else {
126126 // Service worker found. Proceed as normal.
127- registerValidSW ( swUrl , config ) ;
127+ registerValidSW ( swUrl , config )
128128 }
129129 } )
130130 . catch ( ( ) => {
131131 console . log (
132- 'No internet connection found. App is running in offline mode.'
133- ) ;
134- } ) ;
132+ 'No internet connection found. App is running in offline mode.' ,
133+ )
134+ } )
135135}
136136
137137export function unregister ( ) {
138138 if ( 'serviceWorker' in navigator ) {
139139 navigator . serviceWorker . ready . then ( registration => {
140- registration . unregister ( ) ;
141- } ) ;
140+ registration . unregister ( )
141+ } )
142142 }
143143}
0 commit comments