Skip to content

Commit 83609a3

Browse files
fix: do not start multiple watchers
In some cases (for example `tns preview` and scan QR code simultaneously with several devices) we start multiple watchers per platform. We should always have single watcher per platform (one from webpack and one native in fact).
1 parent 7d4f742 commit 83609a3

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lib/controllers/prepare-controller.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,24 @@ export class PrepareController extends EventEmitter {
8080
nativeFilesWatcher: null,
8181
webpackCompilerProcess: null
8282
};
83-
}
83+
await this.startJSWatcherWithPrepare(platformData, projectData, prepareData); // -> start watcher + initial compilation
84+
const hasNativeChanges = await this.startNativeWatcherWithPrepare(platformData, projectData, prepareData); // -> start watcher + initial prepare
85+
const result = { platform: platformData.platformNameLowerCase, hasNativeChanges };
8486

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

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

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

96-
if (this.persistedData && this.persistedData.length) {
97-
this.emitPrepareEvent({ files: [], hasOnlyHotUpdateFiles: false, hasNativeChanges: result.hasNativeChanges, hmrData: null, platform: platformData.platformNameLowerCase });
99+
return result;
98100
}
99-
100-
return result;
101101
}
102102

103103
private async startJSWatcherWithPrepare(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<void> {

0 commit comments

Comments
 (0)