diff --git a/crates/next-core/js/src/dev/hmr-client.ts b/crates/next-core/js/src/dev/hmr-client.ts index 9251e8f93e648..3e94cf5c1fb68 100644 --- a/crates/next-core/js/src/dev/hmr-client.ts +++ b/crates/next-core/js/src/dev/hmr-client.ts @@ -107,7 +107,7 @@ type AggregatedUpdates = { }; // we aggregate all updates until the issues are resolved -const chunksWithUpdates: Map = new Map(); +const chunksWithUpdates: Map = new Map(); function aggregateUpdates( msg: ServerMessage, @@ -116,6 +116,15 @@ function aggregateUpdates( const key = resourceKey(msg.resource); const aggregated = chunksWithUpdates.get(key); + if (msg.type === "issues" && aggregated == null && hasIssues) { + // add an empty record to make sure we don't call `onBuildOk` + chunksWithUpdates.set(key, { + added: {}, + modified: {}, + deleted: new Set(), + }); + } + if (msg.type === "issues" && aggregated != null) { if (!hasIssues) { chunksWithUpdates.delete(key); @@ -248,17 +257,15 @@ function handleSocketMessage(msg: ServerMessage) { if (hasIssues) return; + const runHooks = chunksWithUpdates.size === 0; + if (aggregatedMsg.type !== "issues") { - onBeforeRefresh(); + if (runHooks) onBeforeRefresh(); triggerUpdate(aggregatedMsg); - if (chunksWithUpdates.size === 0) { - onRefresh(); - } + if (runHooks) onRefresh(); } - if (chunksWithUpdates.size === 0) { - onBuildOk(); - } + if (runHooks) onBuildOk(); } export function subscribeToChunkUpdate(