Skip to content

Commit 729cdf2

Browse files
committed
fix(dev-server): avoid Promise in dev server client
1 parent 37e50e3 commit 729cdf2

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

src/dev-server/dev-client/app-update.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { hmrComponents } from './hmr-components';
44
import { hmrExternalStyles } from './hmr-external-styles';
55
import { hmrImages } from './hmr-images';
66
import { hmrInlineStyles } from './hmr-inline-styles';
7-
import { logBuild, logReload } from './logger';
7+
import { logBuild, logReload, logWarn } from './logger';
88
import { 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
}

src/dev-server/dev-client/init-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function initClient(win: d.DevClientWindow, doc: Document, config: d.DevC
2828
// what's expected like /
2929
// we're doing this so we can force the server
3030
// worker to unregister, but do not fully reload the page yet
31-
appReset(win, config).then(() => {
31+
appReset(win, config, () => {
3232
initClientWebSocket(win);
3333
});
3434

0 commit comments

Comments
 (0)