Skip to content

Commit 5da6baf

Browse files
chenjiahanCopilot
andauthored
perf(hmr): no need to get assets info (#6296)
Co-authored-by: Copilot <[email protected]>
1 parent 3b8e77d commit 5da6baf

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

packages/core/src/server/socketServer.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export class SocketServer {
8888

8989
private reportedBrowserLogs: Set<string> = new Set();
9090

91+
private currentHash: Map<string, string> = new Map();
92+
9193
constructor(
9294
context: InternalContext,
9395
options: DevConfig,
@@ -332,10 +334,9 @@ export class SocketServer {
332334
return null;
333335
}
334336

335-
const defaultStats: Record<string, boolean> = {
337+
const defaultStats: Rspack.StatsOptions = {
336338
all: false,
337339
hash: true,
338-
assets: true,
339340
warnings: true,
340341
warningsCount: true,
341342
errors: true,
@@ -383,7 +384,7 @@ export class SocketServer {
383384
const newInitialChunks: Set<string> = new Set();
384385
if (statsJson.entrypoints) {
385386
for (const entrypoint of Object.values(statsJson.entrypoints)) {
386-
const chunks = entrypoint.chunks;
387+
const { chunks } = entrypoint;
387388

388389
if (!Array.isArray(chunks)) {
389390
continue;
@@ -411,19 +412,22 @@ export class SocketServer {
411412
return;
412413
}
413414

414-
const shouldEmit =
415-
!force &&
416-
statsJson &&
417-
!statsJson.errorsCount &&
418-
statsJson.assets &&
419-
statsJson.assets.every((asset: any) => !asset.emitted);
420-
421-
if (shouldEmit) {
422-
this.sockWrite({ type: 'ok' }, token);
423-
return;
424-
}
425-
426415
if (statsJson.hash) {
416+
const prevHash = this.currentHash.get(token);
417+
this.currentHash.set(token, statsJson.hash);
418+
419+
// If build hash is not changed and there is no error or warning, skip emit
420+
const shouldEmit =
421+
!force &&
422+
!statsJson.errorsCount &&
423+
!statsJson.warningsCount &&
424+
prevHash === statsJson.hash;
425+
426+
if (shouldEmit) {
427+
this.sockWrite({ type: 'ok' }, token);
428+
return;
429+
}
430+
427431
this.sockWrite(
428432
{
429433
type: 'hash',
@@ -469,7 +473,6 @@ export class SocketServer {
469473
}
470474

471475
this.sockWrite({ type: 'ok' }, token);
472-
return;
473476
}
474477

475478
// send message to connecting socket

0 commit comments

Comments
 (0)