Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 07f918e

Browse files
committed
fix(error): reload immediately after js/html update
1 parent 10cf07e commit 07f918e

File tree

4 files changed

+55
-30
lines changed

4 files changed

+55
-30
lines changed

bin/ion-dev.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,15 @@ window.IonicDevServer = {
216216
}, 50);
217217

218218
} else {
219-
status = msg.data.diagnosticsHtml ? 'error' : 'success';
220-
221219
clearTimeout(this.toastTimerId);
222220

221+
if (msg.data.reloadApp) {
222+
this.reloadApp();
223+
return;
224+
}
225+
226+
status = msg.data.diagnosticsHtml ? 'error' : 'success';
227+
223228
var toastEle = document.getElementById('ion-diagnostics-toast');
224229
if (toastEle) {
225230
toastEle.classList.remove('ion-diagnostics-toast-active');

src/build.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BuildContext, BuildState } from './util/interfaces';
1+
import { BuildContext, BuildState, BuildUpdateMessage } from './util/interfaces';
22
import { BuildError } from './util/errors';
33
import { bundle, bundleUpdate } from './bundle';
44
import { clean } from './clean';
@@ -45,6 +45,8 @@ function buildProd(context: BuildContext) {
4545
// sync empty the www/build directory
4646
clean(context);
4747

48+
buildId++;
49+
4850
// async tasks
4951
// these can happen all while other tasks are running
5052
const copyPromise = copy(context);
@@ -90,6 +92,8 @@ function buildDev(context: BuildContext) {
9092
// sync empty the www/build directory
9193
clean(context);
9294

95+
buildId++;
96+
9397
// async tasks
9498
// these can happen all while other tasks are running
9599
const copyPromise = copy(context);
@@ -121,8 +125,13 @@ export function buildUpdate(event: string, filePath: string, context: BuildConte
121125
return new Promise(resolve => {
122126
const logger = new Logger('build');
123127

124-
buildUpdateId++;
125-
emit(EventType.BuildUpdateStarted, buildUpdateId);
128+
buildId++;
129+
130+
const buildUpdateMsg: BuildUpdateMessage = {
131+
buildId: buildId,
132+
reloadApp: false
133+
};
134+
emit(EventType.BuildUpdateStarted, buildUpdateMsg);
126135

127136
function buildTasksDone(resolveValue: BuildTaskResolveValue) {
128137
// all build tasks have been resolved or one of them
@@ -131,13 +140,13 @@ export function buildUpdate(event: string, filePath: string, context: BuildConte
131140
parallelTasksPromise.then(() => {
132141
// all parallel tasks are also done
133142
// so now we're done done
134-
emit(EventType.BuildUpdateCompleted, buildUpdateId);
135-
136-
if (resolveValue.requiresRefresh) {
137-
// emit that we need to do a full page refresh
138-
emit(EventType.ReloadApp);
143+
const buildUpdateMsg: BuildUpdateMessage = {
144+
buildId: buildId,
145+
reloadApp: resolveValue.requiresAppReload
146+
};
147+
emit(EventType.BuildUpdateCompleted, buildUpdateMsg);
139148

140-
} else {
149+
if (!resolveValue.requiresAppReload) {
141150
// just emit that only a certain file changed
142151
// this one is useful when only a sass changed happened
143152
// and the webpack only needs to livereload the css
@@ -169,7 +178,7 @@ export function buildUpdate(event: string, filePath: string, context: BuildConte
169178
.then(buildTasksDone)
170179
.catch(() => {
171180
buildTasksDone({
172-
requiresRefresh: false,
181+
requiresAppReload: false,
173182
changedFile: filePath
174183
});
175184
});
@@ -182,15 +191,15 @@ export function buildUpdate(event: string, filePath: string, context: BuildConte
182191
*/
183192
function buildUpdateTasks(event: string, filePath: string, context: BuildContext) {
184193
const resolveValue: BuildTaskResolveValue = {
185-
requiresRefresh: false,
194+
requiresAppReload: false,
186195
changedFile: filePath
187196
};
188197

189198
return Promise.resolve()
190199
.then(() => {
191200
// TEMPLATE
192201
if (context.templateState === BuildState.RequiresUpdate) {
193-
resolveValue.requiresRefresh = true;
202+
resolveValue.requiresAppReload = true;
194203
return templateUpdate(event, filePath, context);
195204
}
196205
// no template updates required
@@ -200,15 +209,15 @@ function buildUpdateTasks(event: string, filePath: string, context: BuildContext
200209
.then(() => {
201210
// TRANSPILE
202211
if (context.transpileState === BuildState.RequiresUpdate) {
203-
resolveValue.requiresRefresh = true;
212+
resolveValue.requiresAppReload = true;
204213
// we've already had a successful transpile once, only do an update
205214
// not that we've also already started a transpile diagnostics only
206215
// build that only needs to be completed by the end of buildUpdate
207216
return transpileUpdate(event, filePath, context);
208217

209218
} else if (context.transpileState === BuildState.RequiresBuild) {
210219
// run the whole transpile
211-
resolveValue.requiresRefresh = true;
220+
resolveValue.requiresAppReload = true;
212221
return transpile(context);
213222
}
214223
// no transpiling required
@@ -219,12 +228,12 @@ function buildUpdateTasks(event: string, filePath: string, context: BuildContext
219228
// BUNDLE
220229
if (context.bundleState === BuildState.RequiresUpdate) {
221230
// we need to do a bundle update
222-
resolveValue.requiresRefresh = true;
231+
resolveValue.requiresAppReload = true;
223232
return bundleUpdate(event, filePath, context);
224233

225234
} else if (context.bundleState === BuildState.RequiresBuild) {
226235
// we need to do a full bundle build
227-
resolveValue.requiresRefresh = true;
236+
resolveValue.requiresAppReload = true;
228237
return bundle(context);
229238
}
230239
// no bundling required
@@ -254,7 +263,7 @@ function buildUpdateTasks(event: string, filePath: string, context: BuildContext
254263
}
255264

256265
interface BuildTaskResolveValue {
257-
requiresRefresh: boolean;
266+
requiresAppReload: boolean;
258267
changedFile: string;
259268
}
260269

@@ -273,4 +282,4 @@ function buildUpdateParallelTasks(event: string, filePath: string, context: Buil
273282
return Promise.all(parallelTasks);
274283
}
275284

276-
let buildUpdateId = 0;
285+
let buildId = 0;

src/dev-server/notification-server.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Ionic Dev Server: Server Side Logger
2+
import { BuildUpdateMessage, WsMessage } from '../util/interfaces';
23
import { Logger } from '../logger/logger';
34
import { generateRuntimeDiagnosticContent } from '../logger/logger-runtime';
45
import { hasDiagnostics, getDiagnosticsHtmlContent } from '../logger/logger-diagnostics';
@@ -32,24 +33,27 @@ export function createNotificationServer(config: ServeConfig) {
3233
}
3334

3435
// a build update has started, notify the client
35-
on(EventType.BuildUpdateStarted, (buildUpdateId) => {
36+
on(EventType.BuildUpdateStarted, (buildUpdateMsg: BuildUpdateMessage) => {
3637
const msg: WsMessage = {
3738
category: 'buildUpdate',
3839
type: 'started',
3940
data: {
40-
buildUpdateId: buildUpdateId
41+
buildId: buildUpdateMsg.buildId,
42+
reloadApp: buildUpdateMsg.reloadApp,
43+
diagnosticsHtml: null
4144
}
4245
};
4346
queueMessageSend(msg);
4447
});
4548

4649
// a build update has completed, notify the client
47-
on(EventType.BuildUpdateCompleted, (buildUpdateId) => {
50+
on(EventType.BuildUpdateCompleted, (buildUpdateMsg: BuildUpdateMessage) => {
4851
const msg: WsMessage = {
4952
category: 'buildUpdate',
5053
type: 'completed',
5154
data: {
52-
buildUpdateId: buildUpdateId,
55+
buildId: buildUpdateMsg.buildId,
56+
reloadApp: buildUpdateMsg.reloadApp,
5357
diagnosticsHtml: hasDiagnostics(config.buildDir) ? getDiagnosticsHtmlContent(config.buildDir) : null
5458
}
5559
};
@@ -132,9 +136,3 @@ export function createNotificationServer(config: ServeConfig) {
132136
}
133137

134138
}
135-
136-
export interface WsMessage {
137-
category: string;
138-
type: string;
139-
data: any;
140-
}

src/util/interfaces.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,16 @@ export interface PrintLine {
8686
errorCharStart: number;
8787
errorLength: number;
8888
}
89+
90+
91+
export interface WsMessage {
92+
category: string;
93+
type: string;
94+
data: any;
95+
}
96+
97+
98+
export interface BuildUpdateMessage {
99+
buildId: number;
100+
reloadApp: boolean;
101+
}

0 commit comments

Comments
 (0)