Skip to content

Commit 4442612

Browse files
committed
fix(vite): skip the in-app refresh before restarting on Android HMR syncs
Under Vite HMR every file the CLI syncs (bundle.mjs, a static file, a custom Application chunk) is applied by restarting the app. With useHotModuleReload set, the Android sockets live sync still marked every file as a fast sync and asked the app to refresh first, which runs __onLiveSync: it can't reload an app Vite serves, and on Angular it threw "Main entry is missing". The uncaught exception then left the runtime's hasError marker, so the restart crashed with ClassNotFoundException and the CLI waited on the livesync socket. Single-process dev on Android now sends static file and Application changes to the CLI, which reaches this path.
1 parent 15c9aa8 commit 4442612

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

‎lib/services/livesync/android-device-livesync-sockets-service.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ import { ICleanupService } from "../../definitions/cleanup-service";
1414
import { ISpawnCommandInfo } from "../../detached-processes/cleanup-process-definitions";
1515
import { ITempService } from "../../definitions/temp-service";
1616

17+
/**
18+
* Whether a file sync asks the app to refresh itself in place. Never under
19+
* Vite HMR: the dev server updates the app, and every file the CLI syncs
20+
* there is applied by restarting it, while the in-app refresh runs
21+
* `__onLiveSync`, which can't reload an app served by Vite.
22+
*/
23+
export function refreshesInPlaceOnSync(
24+
liveSyncInfo: Pick<ILiveSyncResultInfo, "isFullSync" | "useHotModuleReload">,
25+
projectData: Pick<IProjectData, "bundler">,
26+
): boolean {
27+
return (
28+
!liveSyncInfo.isFullSync &&
29+
!(liveSyncInfo.useHotModuleReload && projectData.bundler === "vite")
30+
);
31+
}
32+
1733
export class AndroidDeviceSocketsLiveSyncService
1834
extends AndroidDeviceLiveSyncServiceBase
1935
implements
@@ -127,7 +143,7 @@ export class AndroidDeviceSocketsLiveSyncService
127143

128144
if (liveSyncInfo.modifiedFilesData.length) {
129145
const canExecuteFastSync =
130-
!liveSyncInfo.isFullSync &&
146+
refreshesInPlaceOnSync(liveSyncInfo, projectData) &&
131147
this.canExecuteFastSyncForPaths(
132148
liveSyncInfo,
133149
liveSyncInfo.modifiedFilesData,
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { assert } from "chai";
2+
import { refreshesInPlaceOnSync } from "../../../lib/services/livesync/android-device-livesync-sockets-service";
3+
4+
describe("refreshesInPlaceOnSync", () => {
5+
it("refreshes an incremental sync", () => {
6+
assert.isTrue(
7+
refreshesInPlaceOnSync(
8+
{ isFullSync: false, useHotModuleReload: true },
9+
{ bundler: "webpack" },
10+
),
11+
);
12+
assert.isTrue(
13+
refreshesInPlaceOnSync(
14+
{ isFullSync: false, useHotModuleReload: false },
15+
{ bundler: "vite" },
16+
),
17+
);
18+
});
19+
20+
it("never refreshes a full sync or a Vite HMR session", () => {
21+
assert.isFalse(
22+
refreshesInPlaceOnSync(
23+
{ isFullSync: true, useHotModuleReload: false },
24+
{ bundler: "webpack" },
25+
),
26+
);
27+
assert.isFalse(
28+
refreshesInPlaceOnSync(
29+
{ isFullSync: false, useHotModuleReload: true },
30+
{ bundler: "vite" },
31+
),
32+
);
33+
});
34+
});

0 commit comments

Comments
 (0)