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: perf #3906

Merged
merged 2 commits into from Oct 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/Server.js
Expand Up @@ -36,13 +36,13 @@ class Server {
this.webSocketProxies = [];
this.sockets = [];
this.compiler = compiler;
this.currentHash = null;
}

static get DEFAULT_STATS() {
return {
all: false,
hash: true,
assets: true,
warnings: true,
errors: true,
errorDetails: false,
Expand Down Expand Up @@ -1970,13 +1970,13 @@ class Server {

// eslint-disable-next-line class-methods-use-this
sendMessage(clients, type, data) {
clients.forEach((client) => {
for (const client of clients) {
// `sockjs` uses `1` to indicate client is ready to accept data
// `ws` uses `WebSocket.OPEN`, but it is mean `1` too
if (client.readyState === 1) {
client.send(JSON.stringify({ type, data }));
}
});
}
}

serveMagicHtml(req, res, next) {
Expand Down Expand Up @@ -2011,15 +2011,15 @@ class Server {
stats &&
(!stats.errors || stats.errors.length === 0) &&
(!stats.warnings || stats.warnings.length === 0) &&
stats.assets &&
stats.assets.every((asset) => !asset.emitted);
this.currentHash === stats.hash;
Copy link
Member Author

Choose a reason for hiding this comment

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

@markjm I remove unnecessary ?? check, because it is redundant, when client connected to dev server we always send stats (so we write currentHash), on initial run we send stats too and write hash (client can connected, but compilation can be still not finished, so after it will be finished we should always send stats, it will be never still-ok)

Copy link
Member Author

Choose a reason for hiding this comment

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

Also don't forget about disconnect, developer can run dev server again and compilation can take time (i.e. client connected, but no stats right now) and we should send stats always too


if (shouldEmit) {
this.sendMessage(clients, "still-ok");

return;
}

this.currentHash = stats.hash;
this.sendMessage(clients, "hash", stats.hash);

if (stats.errors.length > 0 || stats.warnings.length > 0) {
Expand Down