Skip to content

Commit 1ba9720

Browse files
fix: reload on warnings (#4056)
1 parent 5026601 commit 1ba9720

8 files changed

+162
-165
lines changed

client-src/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ const onSocketMessage = {
160160

161161
self.location.reload();
162162
},
163-
warnings(warnings) {
163+
warnings(warnings, params) {
164164
log.warn("Warnings while compiling.");
165165

166166
const printableWarnings = warnings.map((error) => {
@@ -183,6 +183,12 @@ const onSocketMessage = {
183183
if (needShowOverlayForWarnings) {
184184
show("warning", warnings);
185185
}
186+
187+
if (params && params.preventReloading) {
188+
return;
189+
}
190+
191+
reloadApp(options, status);
186192
},
187193
errors(errors) {
188194
log.error("Errors while compiling. Reload prevented.");

client-src/socket.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const socket = function initSocket(url, handlers, reconnect) {
5656
const message = JSON.parse(data);
5757

5858
if (handlers[message.type]) {
59-
handlers[message.type](message.data);
59+
handlers[message.type](message.data, message.params);
6060
}
6161
});
6262
};

lib/Server.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -2148,12 +2148,12 @@ class Server {
21482148
}
21492149

21502150
// eslint-disable-next-line class-methods-use-this
2151-
sendMessage(clients, type, data) {
2151+
sendMessage(clients, type, data, params) {
21522152
for (const client of clients) {
21532153
// `sockjs` uses `1` to indicate client is ready to accept data
21542154
// `ws` uses `WebSocket.OPEN`, but it is mean `1` too
21552155
if (client.readyState === 1) {
2156-
client.send(JSON.stringify({ type, data }));
2156+
client.send(JSON.stringify({ type, data, params }));
21572157
}
21582158
}
21592159
}
@@ -2202,8 +2202,16 @@ class Server {
22022202
this.sendMessage(clients, "hash", stats.hash);
22032203

22042204
if (stats.errors.length > 0 || stats.warnings.length > 0) {
2205+
const hasErrors = stats.errors.length > 0;
2206+
22052207
if (stats.warnings.length > 0) {
2206-
this.sendMessage(clients, "warnings", stats.warnings);
2208+
let params;
2209+
2210+
if (hasErrors) {
2211+
params = { preventReloading: true };
2212+
}
2213+
2214+
this.sendMessage(clients, "warnings", stats.warnings, params);
22072215
}
22082216

22092217
if (stats.errors.length > 0) {

0 commit comments

Comments
 (0)