Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

fix(socket-server): send stats to new connections #102

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions lib/client/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/* eslint-disable global-require, consistent-return */

(function hotClientEntry() {
// eslint-disable-next-line no-underscore-dangle
if (window.__webpackHotClient__) {
return;
}

// eslint-disable-next-line no-underscore-dangle
window.__webpackHotClient__ = {};

Expand Down
20 changes: 12 additions & 8 deletions lib/socket-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ function getServer(options) {
}
};

const send = sendData.bind(null, wss, options);
const sendPayload = (type, data) => {
broadcast(payload(type, data));
};

const send = sendData.bind(null, options, sendPayload);

return Object.assign(wss, { broadcast, close, send });
}
Expand Down Expand Up @@ -68,15 +72,19 @@ function onConnection(server, options) {

// only send stats to newly connected clients, if no previous clients have
// connected and stats has been modified by webpack
if (options.stats && options.stats.toJson && server.clients.size === 1) {
if (options.stats && options.stats.toJson) {
const jsonStats = options.stats.toJson(options.stats);

/* istanbul ignore if */
if (!jsonStats) {
options.log.error('Client Connection: `stats` is undefined');
}

server.send(jsonStats);
const send = (type, data) => {
socket.send(payload(type, data));
};

sendData(options, send, jsonStats);
}
});
}
Expand Down Expand Up @@ -116,11 +124,7 @@ function payload(type, data) {
return stringify({ type, data });
}

function sendData(server, options, stats) {
const send = (type, data) => {
server.broadcast(payload(type, data));
};

function sendData(options, send, stats) {
if (stats.errors && stats.errors.length > 0) {
if (options.send.errors) {
const errors = [].concat(stats.errors).map((error) => strip(error));
Expand Down