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: reload on warnings #4056

Merged
merged 1 commit into from Nov 25, 2021
Merged
Show file tree
Hide file tree
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
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