Skip to content

Commit

Permalink
fix error overlay sometimes now showing (vercel/turborepo#3331)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony authored Jan 19, 2023
1 parent cd02e81 commit df2e429
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions crates/next-core/js/src/dev/hmr-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ type AggregatedUpdates = {
};

// we aggregate all updates until the issues are resolved
const chunksWithUpdates: Map<ChunkPath, AggregatedUpdates> = new Map();
const chunksWithUpdates: Map<ResourceKey, AggregatedUpdates> = new Map();

function aggregateUpdates(
msg: ServerMessage,
Expand All @@ -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);
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit df2e429

Please sign in to comment.