Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error overlay sometimes now showing #3331

Merged
merged 2 commits into from
Jan 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Looks like this can be merged with the if statements below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be, but imo makes it harder to read

// add an empty record to make sure we don't call `onBuildOk`
chunksWithUpdates.set(key, {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We check if there are entries in the map below, so even if we have no updates we insert an empty record to make sure it doesn't think everything is fine

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