@@ -4,7 +4,7 @@ import { hmrComponents } from './hmr-components';
44import { hmrExternalStyles } from './hmr-external-styles' ;
55import { hmrImages } from './hmr-images' ;
66import { hmrInlineStyles } from './hmr-inline-styles' ;
7- import { logBuild , logReload } from './logger' ;
7+ import { logBuild , logReload , logWarn } from './logger' ;
88import { onBuildResults } from './build-events' ;
99
1010
@@ -33,7 +33,7 @@ function appUpdate(win: d.DevClientWindow, doc: Document, config: d.DevClientCon
3333 // let's make sure the url is at the root
3434 // and we've unregistered any existing service workers
3535 // then let's refresh the page from the root of the server
36- appReset ( win , config ) . then ( ( ) => {
36+ appReset ( win , config , ( ) => {
3737 logReload ( `Initial load` ) ;
3838 win . location . reload ( true ) ;
3939 } ) ;
@@ -116,26 +116,33 @@ function appHmr(win: Window, doc: Document, hmr: d.HotModuleReplacement) {
116116}
117117
118118
119- export function appReset ( win : d . DevClientWindow , config : d . DevClientConfig ) {
119+ export function appReset ( win : d . DevClientWindow , config : d . DevClientConfig , cb : ( ) => void ) {
120120 // we're probably at some ugly url
121121 // let's update the url to be the expect root url: /
122+ // avoiding Promise to keep things simple for our ie11 buddy
122123 win . history . replaceState ( { } , 'App' , config . basePath ) ;
123124
124- if ( ! win . navigator . serviceWorker ) {
125- return Promise . resolve ( ) ;
125+ if ( ! win . navigator . serviceWorker || ! win . navigator . serviceWorker . getRegistration ) {
126+ cb ( ) ;
127+
128+ } else {
129+ // it's possible a service worker is already registered
130+ // for this localhost url from some other app's development
131+ // let's ensure we entirely remove the service worker for this domain
132+ win . navigator . serviceWorker . getRegistration ( ) . then ( swRegistration => {
133+ if ( swRegistration ) {
134+ swRegistration . unregister ( ) . then ( hasUnregistered => {
135+ if ( hasUnregistered ) {
136+ logBuild ( `unregistered service worker` ) ;
137+ }
138+ cb ( ) ;
139+ } ) ;
140+ } else {
141+ cb ( ) ;
142+ }
143+ } ) . catch ( err => {
144+ logWarn ( 'Service Worker' , err ) ;
145+ cb ( ) ;
146+ } ) ;
126147 }
127-
128- // it's possible a service worker is already registered
129- // for this localhost url from some other app's development
130- // let's ensure we entirely remove the service worker for this domain
131- return win . navigator . serviceWorker . getRegistration ( ) . then ( swRegistration => {
132- if ( swRegistration ) {
133- return swRegistration . unregister ( ) . then ( hasUnregistered => {
134- if ( hasUnregistered ) {
135- logBuild ( `unregistered service worker` ) ;
136- }
137- } ) ;
138- }
139- return Promise . resolve ( ) ;
140- } ) ;
141148}
0 commit comments