Skip to content

Commit b7595b5

Browse files
fix: remove webpackCompilationComplete handler correctly on prepare
Commands using prepare of project (and using SK) should remove their handlers for webpackCompilerService's `webpackCompilationComplete` event. This is not happening and whenever we start new prepartion of the project, we attach new handler. This causes issues when running on device in Sidekick, closing the current app, open it again and try to livesync a change - we have many handlers for prepareReadyEvent and this causes multiple livesync operations.
1 parent 713a817 commit b7595b5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/controllers/prepare-controller.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class PrepareController extends EventEmitter {
1414
private watchersData: IDictionary<IDictionary<IPlatformWatcherData>> = {};
1515
private isInitialPrepareReady = false;
1616
private persistedData: IFilesChangeEventData[] = [];
17+
private webpackCompilerHandler: any = null;
1718

1819
constructor(
1920
private $platformController: IPlatformController,
@@ -46,7 +47,8 @@ export class PrepareController extends EventEmitter {
4647
}
4748

4849
if (this.watchersData && this.watchersData[projectDir] && this.watchersData[projectDir][platformLowerCase] && this.watchersData[projectDir][platformLowerCase].hasWebpackCompilerProcess) {
49-
await this.$webpackCompilerService.stopWebpackCompiler(platform);
50+
await this.$webpackCompilerService.stopWebpackCompiler(platformLowerCase);
51+
this.$webpackCompilerService.removeListener(WEBPACK_COMPILATION_COMPLETE, this.webpackCompilerHandler);
5052
this.watchersData[projectDir][platformLowerCase].hasWebpackCompilerProcess = false;
5153
}
5254
}
@@ -110,11 +112,14 @@ export class PrepareController extends EventEmitter {
110112

111113
private async startJSWatcherWithPrepare(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<void> {
112114
if (!this.watchersData[projectData.projectDir][platformData.platformNameLowerCase].hasWebpackCompilerProcess) {
113-
this.$webpackCompilerService.on(WEBPACK_COMPILATION_COMPLETE, data => {
115+
const handler = (data: any) => {
114116
if (data.platform.toLowerCase() === platformData.platformNameLowerCase) {
115117
this.emitPrepareEvent({ ...data, hasNativeChanges: false });
116118
}
117-
});
119+
};
120+
121+
this.webpackCompilerHandler = handler.bind(this);
122+
this.$webpackCompilerService.on(WEBPACK_COMPILATION_COMPLETE, this.webpackCompilerHandler);
118123

119124
this.watchersData[projectData.projectDir][platformData.platformNameLowerCase].hasWebpackCompilerProcess = true;
120125
await this.$webpackCompilerService.compileWithWatch(platformData, projectData, prepareData);

0 commit comments

Comments
 (0)