Skip to content

Commit 596c651

Browse files
fix: handle cases where hmrData in preview can be null
In case the hmrData is not passed during initial sync, the code will fail with some unexpected exception. Handle the case and fix unit tests which are successful, but actually throw unhandled error in one of the event handlers.
1 parent 188b3bb commit 596c651

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/controllers/preview-app-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class PreviewAppController extends EventEmitter implements IPreviewAppCon
138138
@performanceLog()
139139
private async handlePrepareReadyEvent(data: IPreviewAppLiveSyncData, currentPrepareData: IFilesChangeEventData) {
140140
const { hmrData, files, platform } = currentPrepareData;
141-
const platformHmrData = _.cloneDeep(hmrData);
141+
const platformHmrData = _.cloneDeep(hmrData) || <IPlatformHmrData>{};
142142
const connectedDevices = this.$previewDevicesService.getDevicesForPlatform(platform);
143143
if (!connectedDevices || !connectedDevices.length) {
144144
this.$logger.warn(`Unable to find any connected devices for platform '${platform}'. In order to execute live sync, open your Preview app and optionally re-scan the QR code using the Playground app.`);

test/services/playground/preview-app-livesync-service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ function createTestInjector(options?: {
171171
mapFilePath: (filePath: string) => path.join(path.join(platformsDirPath, "app"), path.relative(path.join(projectDirPath, "app"), filePath))
172172
});
173173
injector.register("previewDevicesService", {
174-
getConnectedDevices: () => [deviceMockData]
174+
getConnectedDevices: () => [deviceMockData],
175+
getDevicesForPlatform: (platform: string): Device[] => [deviceMockData]
175176
});
176177
injector.register("previewAppFilesService", PreviewAppFilesService);
177178
injector.register("previewQrCodeService", {

0 commit comments

Comments
 (0)