Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: reload on warnings (#4056)
  • Loading branch information
alexander-akait committed Nov 25, 2021
1 parent 5026601 commit 1ba9720
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 165 deletions.
8 changes: 7 additions & 1 deletion client-src/index.js
Expand Up @@ -160,7 +160,7 @@ const onSocketMessage = {

self.location.reload();
},
warnings(warnings) {
warnings(warnings, params) {
log.warn("Warnings while compiling.");

const printableWarnings = warnings.map((error) => {
Expand All @@ -183,6 +183,12 @@ const onSocketMessage = {
if (needShowOverlayForWarnings) {
show("warning", warnings);
}

if (params && params.preventReloading) {
return;
}

reloadApp(options, status);
},
errors(errors) {
log.error("Errors while compiling. Reload prevented.");
Expand Down
2 changes: 1 addition & 1 deletion client-src/socket.js
Expand Up @@ -56,7 +56,7 @@ const socket = function initSocket(url, handlers, reconnect) {
const message = JSON.parse(data);

if (handlers[message.type]) {
handlers[message.type](message.data);
handlers[message.type](message.data, message.params);
}
});
};
Expand Down
14 changes: 11 additions & 3 deletions lib/Server.js
Expand Up @@ -2148,12 +2148,12 @@ class Server {
}

// eslint-disable-next-line class-methods-use-this
sendMessage(clients, type, data) {
sendMessage(clients, type, data, params) {
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 }));
client.send(JSON.stringify({ type, data, params }));
}
}
}
Expand Down Expand Up @@ -2202,8 +2202,16 @@ class Server {
this.sendMessage(clients, "hash", stats.hash);

if (stats.errors.length > 0 || stats.warnings.length > 0) {
const hasErrors = stats.errors.length > 0;

if (stats.warnings.length > 0) {
this.sendMessage(clients, "warnings", stats.warnings);
let params;

if (hasErrors) {
params = { preventReloading: true };
}

this.sendMessage(clients, "warnings", stats.warnings, params);
}

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

0 comments on commit 1ba9720

Please sign in to comment.