Skip to content

Commit

Permalink
fix: perf (#3906)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Oct 4, 2021
1 parent 625b9a8 commit f6e2a19
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/Server.js
Original file line number Diff line number Diff line change
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;

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

0 comments on commit f6e2a19

Please sign in to comment.