Skip to content

Commit 970a7d7

Browse files
authored
fix: improve message for static content changes (#3289)
1 parent 3a74932 commit 970a7d7

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

client-src/index.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,22 @@ const onSocketMessage = {
137137

138138
reloadApp(options, status);
139139
},
140-
'content-changed': function contentChanged() {
141-
log.info('Content base changed. Reloading...');
140+
// TODO: remove in v5 in favor of 'static-changed'
141+
'content-changed': function contentChanged(file) {
142+
log.info(
143+
`${
144+
file ? `"${file}"` : 'Content'
145+
} from static directory was changed. Reloading...`
146+
);
147+
148+
self.location.reload();
149+
},
150+
'static-changed': function staticChanged(file) {
151+
log.info(
152+
`${
153+
file ? `"${file}"` : 'Content'
154+
} from static directory was changed. Reloading...`
155+
);
142156

143157
self.location.reload();
144158
},

lib/Server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ class Server {
11211121
// disabling refreshing on changing the content
11221122
if (this.options.liveReload) {
11231123
watcher.on('change', () => {
1124-
this.sockWrite(this.sockets, 'content-changed');
1124+
this.sockWrite(this.sockets, 'static-changed', watchPath);
11251125
});
11261126
}
11271127

test/client/__snapshots__/index.test.js.snap.webpack4

+8-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ Array [
8080
]
8181
`;
8282

83-
exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content base changed. Reloading..."`;
83+
exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content from static directory was changed. Reloading..."`;
84+
85+
exports[`index should run onSocketMessage['content-changed'](file) 1`] = `"\\"/public/assets/index.html\\" from static directory was changed. Reloading..."`;
86+
87+
exports[`index should run onSocketMessage['static-changed'] 1`] = `"Content from static directory was changed. Reloading..."`;
88+
89+
exports[`index should run onSocketMessage['static-changed'](file) 1`] = `"\\"/static/assets/index.html\\" from static directory was changed. Reloading..."`;
8490

8591
exports[`index should run onSocketMessage['still-ok'] 1`] = `"Nothing changed."`;
8692

@@ -103,6 +109,7 @@ Array [
103109
"overlay": [Function],
104110
"progress": [Function],
105111
"progress-update": [Function],
112+
"static-changed": [Function],
106113
"still-ok": [Function],
107114
"warnings": [Function],
108115
},

test/client/__snapshots__/index.test.js.snap.webpack5

+8-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ Array [
8080
]
8181
`;
8282

83-
exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content base changed. Reloading..."`;
83+
exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content from static directory was changed. Reloading..."`;
84+
85+
exports[`index should run onSocketMessage['content-changed'](file) 1`] = `"\\"/public/assets/index.html\\" from static directory was changed. Reloading..."`;
86+
87+
exports[`index should run onSocketMessage['static-changed'] 1`] = `"Content from static directory was changed. Reloading..."`;
88+
89+
exports[`index should run onSocketMessage['static-changed'](file) 1`] = `"\\"/static/assets/index.html\\" from static directory was changed. Reloading..."`;
8490

8591
exports[`index should run onSocketMessage['still-ok'] 1`] = `"Nothing changed."`;
8692

@@ -103,6 +109,7 @@ Array [
103109
"overlay": [Function],
104110
"progress": [Function],
105111
"progress-update": [Function],
112+
"static-changed": [Function],
106113
"still-ok": [Function],
107114
"warnings": [Function],
108115
},

test/client/index.test.js

+21
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,27 @@ describe('index', () => {
185185
expect(self.location.reload).toBeCalled();
186186
});
187187

188+
test("should run onSocketMessage['content-changed'](file)", () => {
189+
onSocketMessage['content-changed']('/public/assets/index.html');
190+
191+
expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
192+
expect(self.location.reload).toBeCalled();
193+
});
194+
195+
test("should run onSocketMessage['static-changed']", () => {
196+
onSocketMessage['static-changed']();
197+
198+
expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
199+
expect(self.location.reload).toBeCalled();
200+
});
201+
202+
test("should run onSocketMessage['static-changed'](file)", () => {
203+
onSocketMessage['static-changed']('/static/assets/index.html');
204+
205+
expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
206+
expect(self.location.reload).toBeCalled();
207+
});
208+
188209
test('should run onSocketMessage.warnings', () => {
189210
{
190211
const res = onSocketMessage.warnings([

0 commit comments

Comments
 (0)