Skip to content

fix: handle preview issues #4790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions lib/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,24 @@ export class PrepareController extends EventEmitter {
nativeFilesWatcher: null,
webpackCompilerProcess: null
};
}
await this.startJSWatcherWithPrepare(platformData, projectData, prepareData); // -> start watcher + initial compilation
const hasNativeChanges = await this.startNativeWatcherWithPrepare(platformData, projectData, prepareData); // -> start watcher + initial prepare
const result = { platform: platformData.platformNameLowerCase, hasNativeChanges };

await this.startJSWatcherWithPrepare(platformData, projectData, prepareData); // -> start watcher + initial compilation
const hasNativeChanges = await this.startNativeWatcherWithPrepare(platformData, projectData, prepareData); // -> start watcher + initial prepare
const hasPersistedDataWithNativeChanges = this.persistedData.find(data => data.platform === result.platform && data.hasNativeChanges);
if (hasPersistedDataWithNativeChanges) {
result.hasNativeChanges = true;
}

const result = { platform: platformData.platformNameLowerCase, hasNativeChanges };
const hasPersistedDataWithNativeChanges = this.persistedData.find(data => data.platform === result.platform && data.hasNativeChanges);
if (hasPersistedDataWithNativeChanges) {
result.hasNativeChanges = true;
}
// TODO: Do not persist this in `this` context. Also it should be per platform.
this.isInitialPrepareReady = true;

this.isInitialPrepareReady = true;
if (this.persistedData && this.persistedData.length) {
this.emitPrepareEvent({ files: [], hasOnlyHotUpdateFiles: false, hasNativeChanges: result.hasNativeChanges, hmrData: null, platform: platformData.platformNameLowerCase });
}

if (this.persistedData && this.persistedData.length) {
this.emitPrepareEvent({ files: [], hasOnlyHotUpdateFiles: false, hasNativeChanges: result.hasNativeChanges, hmrData: null, platform: platformData.platformNameLowerCase });
return result;
}

return result;
}

private async startJSWatcherWithPrepare(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<void> {
Expand Down
33 changes: 22 additions & 11 deletions lib/controllers/preview-app-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { PrepareDataService } from "../services/prepare-data-service";
import { PreviewAppLiveSyncEvents } from "../services/livesync/playground/preview-app-constants";

export class PreviewAppController extends EventEmitter implements IPreviewAppController {
private deviceInitializationPromise: IDictionary<Promise<FilesPayload>> = {};
private deviceInitializationPromise: IDictionary<boolean> = {};
private platformPrepareHandlers: IDictionary<boolean> = {};
private promise = Promise.resolve();

constructor(
Expand Down Expand Up @@ -49,9 +50,14 @@ export class PreviewAppController extends EventEmitter implements IPreviewAppCon
}

if (this.deviceInitializationPromise[device.id]) {
return this.deviceInitializationPromise[device.id];
// In some cases devices are reported several times during initialization.
// In case we are already preparing the sending of initial files, disregard consecutive requests for initial files
// until we send the files we are currently preparing.
return null;
}

this.deviceInitializationPromise[device.id] = true;

if (device.uniqueId) {
await this.$analyticsService.trackEventActionInGoogleAnalytics({
action: TrackActionNames.PreviewAppData,
Expand All @@ -68,20 +74,25 @@ export class PreviewAppController extends EventEmitter implements IPreviewAppCon

await this.$previewAppPluginsService.comparePluginsOnDevice(data, device);

this.$prepareController.on(PREPARE_READY_EVENT_NAME, async currentPrepareData => {
await this.handlePrepareReadyEvent(data, currentPrepareData.hmrData, currentPrepareData.files, device.platform);
});
if (!this.platformPrepareHandlers[device.platform]) {
// TODO: Unset this property once the preview operation for this platform is stopped
this.platformPrepareHandlers[device.platform] = true;

// TODO: Remove the handler once the preview operation for this platform is stopped
this.$prepareController.on(PREPARE_READY_EVENT_NAME, async currentPrepareData => {
await this.handlePrepareReadyEvent(data, currentPrepareData.hmrData, currentPrepareData.files, device.platform);
});

if (!data.env) { data.env = { }; }
}

data.env = data.env || {};
data.env.externals = this.$previewAppPluginsService.getExternalPlugins(device);

const prepareData = this.$prepareDataService.getPrepareData(data.projectDir, device.platform.toLowerCase(), { ...data, nativePrepare: { skipNativePrepare: true }, watch: true });
const prepareData = this.$prepareDataService.getPrepareData(data.projectDir, device.platform.toLowerCase(), { ...data, nativePrepare: { skipNativePrepare: true }, watch: true });
await this.$prepareController.prepare(prepareData);

this.deviceInitializationPromise[device.id] = this.getInitialFilesForPlatformSafe(data, device.platform);

try {
const payloads = await this.deviceInitializationPromise[device.id];
const payloads = await this.getInitialFilesForPlatformSafe(data, device.platform);
return payloads;
} finally {
this.deviceInitializationPromise[device.id] = null;
Expand Down Expand Up @@ -116,7 +127,7 @@ export class PreviewAppController extends EventEmitter implements IPreviewAppCon
if (status === HmrConstants.HMR_ERROR_STATUS) {
const originalUseHotModuleReload = data.useHotModuleReload;
data.useHotModuleReload = false;
await this.syncFilesForPlatformSafe(data, { filesToSync: platformHmrData.fallbackFiles }, platform, previewDevice.id );
await this.syncFilesForPlatformSafe(data, { filesToSync: platformHmrData.fallbackFiles }, platform, previewDevice.id);
data.useHotModuleReload = originalUseHotModuleReload;
}
}));
Expand Down
2 changes: 0 additions & 2 deletions lib/services/livesync/playground/preview-qr-code-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export class PreviewQrCodeService implements IPreviewQrCodeService {
const qrCodeUrl = this.$previewSdkService.getQrCodeUrl(options);
const url = await this.getShortenUrl(qrCodeUrl);

this.$logger.info("======== qrCodeUrl ======== ", qrCodeUrl);

this.$logger.info();
const message = `${EOL} Generating qrcode for url ${url}.`;
this.$logger.trace(message);
Expand Down