From bf2dae4e953ce6f92d6627fd61114172b597b275 Mon Sep 17 00:00:00 2001 From: Leah Date: Mon, 16 Jan 2023 18:16:55 +0100 Subject: [PATCH 1/2] fix error overlay not showing sometimes --- crates/next-core/js/src/dev/hmr-client.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/next-core/js/src/dev/hmr-client.ts b/crates/next-core/js/src/dev/hmr-client.ts index 9251e8f93e648a..fec8347b39e92b 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); From f95e7966db0ccb32c65ed4cbd5f73d7455b2e183 Mon Sep 17 00:00:00 2001 From: Leah Date: Mon, 16 Jan 2023 18:20:56 +0100 Subject: [PATCH 2/2] don't call `onBeforeRefresh` if there are chunks with issues --- crates/next-core/js/src/dev/hmr-client.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/next-core/js/src/dev/hmr-client.ts b/crates/next-core/js/src/dev/hmr-client.ts index fec8347b39e92b..3e94cf5c1fb689 100644 --- a/crates/next-core/js/src/dev/hmr-client.ts +++ b/crates/next-core/js/src/dev/hmr-client.ts @@ -257,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(