@@ -144,10 +144,10 @@ export class RunController extends EventEmitter implements IRunController {
144144 return this . $liveSyncProcessDataService . getDeviceDescriptors ( data . projectDir ) ;
145145 }
146146
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 > {
148148 const result = deviceDescriptor . debuggingEnabled ?
149149 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 ) ;
151151
152152 const device = liveSyncResultInfo . deviceAppData . device ;
153153
@@ -181,14 +181,15 @@ export class RunController extends EventEmitter implements IRunController {
181181 }
182182
183183 @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 > {
185185 const result = { didRestart : false } ;
186186 const platform = liveSyncResultInfo . deviceAppData . platform ;
187187 const applicationIdentifier = projectData . projectIdentifiers [ platform . toLowerCase ( ) ] ;
188188 const platformLiveSyncService = this . $liveSyncServiceResolver . resolveLiveSyncService ( platform ) ;
189189
190190 try {
191- let shouldRestart = filesChangeEventData && ( filesChangeEventData . hasNativeChanges || ! filesChangeEventData . hasOnlyHotUpdateFiles ) ;
191+ const isFullSync = filesChangeEventData && ( filesChangeEventData . hasNativeChanges || ! filesChangeEventData . hasOnlyHotUpdateFiles ) ;
192+ let shouldRestart = isFullSync ;
192193 if ( ! shouldRestart ) {
193194 shouldRestart = await platformLiveSyncService . shouldRestart ( projectData , liveSyncResultInfo ) ;
194195 }
@@ -197,6 +198,12 @@ export class RunController extends EventEmitter implements IRunController {
197198 shouldRestart = ! await platformLiveSyncService . tryRefreshApplication ( projectData , liveSyncResultInfo ) ;
198199 }
199200
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+
200207 if ( shouldRestart ) {
201208 this . emit ( DEBUGGER_DETACHED_EVENT_NAME , { deviceIdentifier : liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier } ) ;
202209 await platformLiveSyncService . restartApplication ( projectData , liveSyncResultInfo ) ;
@@ -360,11 +367,14 @@ export class RunController extends EventEmitter implements IRunController {
360367
361368 try {
362369 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 ;
363373 const watchInfo = {
364374 liveSyncDeviceData : deviceDescriptor ,
365375 projectData,
366376 filesToRemove : < any > [ ] ,
367- filesToSync : data . files ,
377+ filesToSync,
368378 hmrData : data . hmrData ,
369379 useHotModuleReload : liveSyncInfo . useHotModuleReload ,
370380 force : liveSyncInfo . force ,
@@ -391,16 +401,21 @@ export class RunController extends EventEmitter implements IRunController {
391401 }
392402
393403 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 ) ;
396413
397414 if ( ! liveSyncResultInfo . didRecover && isInHMRMode ) {
398415 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 ( ) ;
404419 liveSyncResultInfo . isFullSync = true ;
405420 await this . refreshApplication ( projectData , liveSyncResultInfo , data , deviceDescriptor ) ;
406421 }
0 commit comments