Skip to content

Commit ad4be35

Browse files
committed
fix: recover android application if with hmr and in ErrorActivity
1 parent 8069439 commit ad4be35

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

lib/definitions/livesync.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,15 @@ interface ILiveSyncWatchInfo extends IProjectDataComposition, IHasUseHotModuleRe
349349
isReinstalled: boolean;
350350
syncAllFiles: boolean;
351351
liveSyncDeviceInfo: ILiveSyncDeviceInfo;
352+
hmrData: { hash: string; fallbackFiles: IDictionary<string[]> };
352353
force?: boolean;
353354
}
354355

355356
interface ILiveSyncResultInfo extends IHasUseHotModuleReloadOption {
356357
modifiedFilesData: Mobile.ILocalToDevicePathData[];
357358
isFullSync: boolean;
358359
deviceAppData: Mobile.IDeviceAppData;
360+
didRecover?: boolean
359361
}
360362

361363
interface IAndroidLiveSyncResultInfo extends ILiveSyncResultInfo, IAndroidLivesyncSyncOperationResult { }

lib/services/livesync/android-livesync-service.ts

+16
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,24 @@ export class AndroidLiveSyncService extends PlatformLiveSyncServiceBase implemen
2424
}
2525

2626
public async liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<IAndroidLiveSyncResultInfo> {
27+
let result = await this.liveSyncWatchActionCore(device, liveSyncInfo);
28+
29+
// When we use hmr, there is only one case when result.didRefresh is false.
30+
// This is the case when the app has crashed and is in ErrorActivity.
31+
// As the app might not have time to apply the patches, we will send the whole bundle.js(fallbackFiles)
32+
if (liveSyncInfo.useHotModuleReload && !result.didRefresh && liveSyncInfo.hmrData && liveSyncInfo.hmrData.hash) {
33+
liveSyncInfo.filesToSync = liveSyncInfo.hmrData.fallbackFiles[device.deviceInfo.platform];
34+
result = await this.liveSyncWatchActionCore(device, liveSyncInfo);
35+
result.didRecover = true;
36+
}
37+
38+
return result;
39+
}
40+
41+
private async liveSyncWatchActionCore(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<IAndroidLiveSyncResultInfo> {
2742
const liveSyncResult = await super.liveSyncWatchAction(device, liveSyncInfo);
2843
const result = await this.finalizeSync(device, liveSyncInfo.projectData, liveSyncResult);
44+
2945
return result;
3046
}
3147

lib/services/livesync/livesync-service.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
666666
filesToSync: currentFilesToSync,
667667
isReinstalled: appInstalledOnDeviceResult.appInstalled,
668668
syncAllFiles: liveSyncData.watchAllFiles,
669+
hmrData: currentHmrData,
669670
useHotModuleReload: liveSyncData.useHotModuleReload,
670671
force: liveSyncData.force
671672
};
@@ -674,11 +675,13 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
674675

675676
await this.refreshApplication(projectData, liveSyncResultInfo, deviceBuildInfoDescriptor.debugOptions, deviceBuildInfoDescriptor.outputPath);
676677

677-
if (liveSyncData.useHotModuleReload && currentHmrData.hash) {
678+
//If didRecover is true, this means we were in ErrorActivity and fallback files were already transfered and app will be restarted.
679+
if (!liveSyncResultInfo.didRecover && liveSyncData.useHotModuleReload && currentHmrData.hash) {
678680
const status = await this.$hmrStatusService.getHmrStatus(device.deviceInfo.identifier, currentHmrData.hash);
679681
if (status === HmrConstants.HMR_ERROR_STATUS) {
680682
settings.filesToSync = currentHmrData.fallbackFiles[device.deviceInfo.platform];
681683
liveSyncResultInfo = await service.liveSyncWatchAction(device, settings);
684+
//We want to force a restart of the application.
682685
liveSyncResultInfo.isFullSync = true;
683686
await this.refreshApplication(projectData, liveSyncResultInfo, deviceBuildInfoDescriptor.debugOptions, deviceBuildInfoDescriptor.outputPath);
684687
}

0 commit comments

Comments
 (0)