diff --git a/lib/definitions/livesync.d.ts b/lib/definitions/livesync.d.ts index d22b1b1ab6..6bf3a8a72e 100644 --- a/lib/definitions/livesync.d.ts +++ b/lib/definitions/livesync.d.ts @@ -349,6 +349,7 @@ interface ILiveSyncWatchInfo extends IProjectDataComposition, IHasUseHotModuleRe isReinstalled: boolean; syncAllFiles: boolean; liveSyncDeviceInfo: ILiveSyncDeviceInfo; + hmrData: { hash: string; fallbackFiles: IDictionary }; force?: boolean; } @@ -356,6 +357,7 @@ interface ILiveSyncResultInfo extends IHasUseHotModuleReloadOption { modifiedFilesData: Mobile.ILocalToDevicePathData[]; isFullSync: boolean; deviceAppData: Mobile.IDeviceAppData; + didRecover?: boolean } interface IAndroidLiveSyncResultInfo extends ILiveSyncResultInfo, IAndroidLivesyncSyncOperationResult { } diff --git a/lib/services/livesync/android-livesync-service.ts b/lib/services/livesync/android-livesync-service.ts index 9821e7e23e..e5bbb166e1 100644 --- a/lib/services/livesync/android-livesync-service.ts +++ b/lib/services/livesync/android-livesync-service.ts @@ -24,8 +24,24 @@ export class AndroidLiveSyncService extends PlatformLiveSyncServiceBase implemen } public async liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise { + let result = await this.liveSyncWatchActionCore(device, liveSyncInfo); + + // When we use hmr, there is only one case when result.didRefresh is false. + // This is the case when the app has crashed and is in ErrorActivity. + // As the app might not have time to apply the patches, we will send the whole bundle.js(fallbackFiles) + if (liveSyncInfo.useHotModuleReload && !result.didRefresh && liveSyncInfo.hmrData && liveSyncInfo.hmrData.hash) { + liveSyncInfo.filesToSync = liveSyncInfo.hmrData.fallbackFiles[device.deviceInfo.platform]; + result = await this.liveSyncWatchActionCore(device, liveSyncInfo); + result.didRecover = true; + } + + return result; + } + + private async liveSyncWatchActionCore(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise { const liveSyncResult = await super.liveSyncWatchAction(device, liveSyncInfo); const result = await this.finalizeSync(device, liveSyncInfo.projectData, liveSyncResult); + return result; } diff --git a/lib/services/livesync/livesync-service.ts b/lib/services/livesync/livesync-service.ts index db13f034f7..063de63e42 100644 --- a/lib/services/livesync/livesync-service.ts +++ b/lib/services/livesync/livesync-service.ts @@ -666,6 +666,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi filesToSync: currentFilesToSync, isReinstalled: appInstalledOnDeviceResult.appInstalled, syncAllFiles: liveSyncData.watchAllFiles, + hmrData: currentHmrData, useHotModuleReload: liveSyncData.useHotModuleReload, force: liveSyncData.force }; @@ -674,11 +675,13 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi await this.refreshApplication(projectData, liveSyncResultInfo, deviceBuildInfoDescriptor.debugOptions, deviceBuildInfoDescriptor.outputPath); - if (liveSyncData.useHotModuleReload && currentHmrData.hash) { + //If didRecover is true, this means we were in ErrorActivity and fallback files were already transfered and app will be restarted. + if (!liveSyncResultInfo.didRecover && liveSyncData.useHotModuleReload && currentHmrData.hash) { const status = await this.$hmrStatusService.getHmrStatus(device.deviceInfo.identifier, currentHmrData.hash); if (status === HmrConstants.HMR_ERROR_STATUS) { settings.filesToSync = currentHmrData.fallbackFiles[device.deviceInfo.platform]; liveSyncResultInfo = await service.liveSyncWatchAction(device, settings); + //We want to force a restart of the application. liveSyncResultInfo.isFullSync = true; await this.refreshApplication(projectData, liveSyncResultInfo, deviceBuildInfoDescriptor.debugOptions, deviceBuildInfoDescriptor.outputPath); }