@@ -144,10 +144,10 @@ export class RunController extends EventEmitter implements IRunController {
144
144
return this . $liveSyncProcessDataService . getDeviceDescriptors ( data . projectDir ) ;
145
145
}
146
146
147
- protected async refreshApplication ( projectData : IProjectData , liveSyncResultInfo : ILiveSyncResultInfo , filesChangeEventData : IFilesChangeEventData , deviceDescriptor : ILiveSyncDeviceDescriptor ) : Promise < IRestartApplicationInfo > {
147
+ protected async refreshApplication ( projectData : IProjectData , liveSyncResultInfo : ILiveSyncResultInfo , filesChangeEventData : IFilesChangeEventData , deviceDescriptor : ILiveSyncDeviceDescriptor , fullSyncAction ?: ( ) => Promise < void > ) : Promise < IRestartApplicationInfo > {
148
148
const result = deviceDescriptor . debuggingEnabled ?
149
149
await this . refreshApplicationWithDebug ( projectData , liveSyncResultInfo , filesChangeEventData , deviceDescriptor ) :
150
- await this . refreshApplicationWithoutDebug ( projectData , liveSyncResultInfo , filesChangeEventData , deviceDescriptor ) ;
150
+ await this . refreshApplicationWithoutDebug ( projectData , liveSyncResultInfo , filesChangeEventData , deviceDescriptor , undefined , fullSyncAction ) ;
151
151
152
152
const device = liveSyncResultInfo . deviceAppData . device ;
153
153
@@ -181,14 +181,15 @@ export class RunController extends EventEmitter implements IRunController {
181
181
}
182
182
183
183
@performanceLog ( )
184
- protected async refreshApplicationWithoutDebug ( projectData : IProjectData , liveSyncResultInfo : ILiveSyncResultInfo , filesChangeEventData : IFilesChangeEventData , deviceDescriptor : ILiveSyncDeviceDescriptor , settings ?: IRefreshApplicationSettings ) : Promise < IRestartApplicationInfo > {
184
+ protected async refreshApplicationWithoutDebug ( projectData : IProjectData , liveSyncResultInfo : ILiveSyncResultInfo , filesChangeEventData : IFilesChangeEventData , deviceDescriptor : ILiveSyncDeviceDescriptor , settings ?: IRefreshApplicationSettings , fullSyncAction ?: ( ) => Promise < void > ) : Promise < IRestartApplicationInfo > {
185
185
const result = { didRestart : false } ;
186
186
const platform = liveSyncResultInfo . deviceAppData . platform ;
187
187
const applicationIdentifier = projectData . projectIdentifiers [ platform . toLowerCase ( ) ] ;
188
188
const platformLiveSyncService = this . $liveSyncServiceResolver . resolveLiveSyncService ( platform ) ;
189
189
190
190
try {
191
- let shouldRestart = filesChangeEventData && ( filesChangeEventData . hasNativeChanges || ! filesChangeEventData . hasOnlyHotUpdateFiles ) ;
191
+ const isFullSync = filesChangeEventData && ( filesChangeEventData . hasNativeChanges || ! filesChangeEventData . hasOnlyHotUpdateFiles ) ;
192
+ let shouldRestart = isFullSync ;
192
193
if ( ! shouldRestart ) {
193
194
shouldRestart = await platformLiveSyncService . shouldRestart ( projectData , liveSyncResultInfo ) ;
194
195
}
@@ -197,6 +198,12 @@ export class RunController extends EventEmitter implements IRunController {
197
198
shouldRestart = ! await platformLiveSyncService . tryRefreshApplication ( projectData , liveSyncResultInfo ) ;
198
199
}
199
200
201
+ if ( ! isFullSync && shouldRestart && fullSyncAction ) {
202
+ this . $logger . trace ( `Syncing all files as the current app state does not support hot updates.` ) ;
203
+ liveSyncResultInfo . didRecover = true ;
204
+ await fullSyncAction ( ) ;
205
+ }
206
+
200
207
if ( shouldRestart ) {
201
208
this . emit ( DEBUGGER_DETACHED_EVENT_NAME , { deviceIdentifier : liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier } ) ;
202
209
await platformLiveSyncService . restartApplication ( projectData , liveSyncResultInfo ) ;
@@ -360,11 +367,14 @@ export class RunController extends EventEmitter implements IRunController {
360
367
361
368
try {
362
369
const platformLiveSyncService = this . $liveSyncServiceResolver . resolveLiveSyncService ( device . deviceInfo . platform ) ;
370
+ const allAppFiles = ( data . hmrData && data . hmrData . fallbackFiles && data . hmrData . fallbackFiles . length ) ?
371
+ data . hmrData . fallbackFiles : data . files ;
372
+ const filesToSync = data . hasOnlyHotUpdateFiles ? data . files : allAppFiles ;
363
373
const watchInfo = {
364
374
liveSyncDeviceData : deviceDescriptor ,
365
375
projectData,
366
376
filesToRemove : < any > [ ] ,
367
- filesToSync : data . files ,
377
+ filesToSync,
368
378
hmrData : data . hmrData ,
369
379
useHotModuleReload : liveSyncInfo . useHotModuleReload ,
370
380
force : liveSyncInfo . force ,
@@ -391,16 +401,21 @@ export class RunController extends EventEmitter implements IRunController {
391
401
}
392
402
393
403
const watchAction = async ( ) : Promise < void > => {
394
- let liveSyncResultInfo = await platformLiveSyncService . liveSyncWatchAction ( device , watchInfo ) ;
395
- await this . refreshApplication ( projectData , liveSyncResultInfo , data , deviceDescriptor ) ;
404
+ const liveSyncResultInfo = await platformLiveSyncService . liveSyncWatchAction ( device , watchInfo ) ;
405
+ const fullSyncAction = async ( ) => {
406
+ watchInfo . filesToSync = allAppFiles ;
407
+ const fullLiveSyncResultInfo = await platformLiveSyncService . liveSyncWatchAction ( device , watchInfo ) ;
408
+ // IMPORTANT: keep the same instance as we rely on side effects
409
+ _ . assign ( liveSyncResultInfo , fullLiveSyncResultInfo ) ;
410
+ } ;
411
+
412
+ await this . refreshApplication ( projectData , liveSyncResultInfo , data , deviceDescriptor , fullSyncAction ) ;
396
413
397
414
if ( ! liveSyncResultInfo . didRecover && isInHMRMode ) {
398
415
const status = await this . $hmrStatusService . getHmrStatus ( device . deviceInfo . identifier , data . hmrData . hash ) ;
399
- // error or timeout
400
- if ( status !== HmrConstants . HMR_SUCCESS_STATUS ) {
401
- watchInfo . filesToSync = data . hmrData . fallbackFiles ;
402
- liveSyncResultInfo = await platformLiveSyncService . liveSyncWatchAction ( device , watchInfo ) ;
403
- // We want to force a restart of the application.
416
+ // the timeout is assumed OK as the app could be blocked on a breakpoint
417
+ if ( status === HmrConstants . HMR_ERROR_STATUS ) {
418
+ await fullSyncAction ( ) ;
404
419
liveSyncResultInfo . isFullSync = true ;
405
420
await this . refreshApplication ( projectData , liveSyncResultInfo , data , deviceDescriptor ) ;
406
421
}
0 commit comments