Skip to content

Commit 80bc5ad

Browse files
authored
Merge pull request #13105 from webpack/bugfix/invalid-only-once
make sure that invalid event is only reported once
2 parents 1f48895 + b525e61 commit 80bc5ad

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

lib/Watching.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class Watching {
5353
this.compiler = compiler;
5454
this.running = false;
5555
this._initial = true;
56+
this._invalidReported = true;
5657
this._needRecords = true;
5758
this.watcher = undefined;
5859
this.pausedWatcher = undefined;
@@ -83,6 +84,7 @@ class Watching {
8384
});
8485
}
8586
this.invalid = false;
87+
this._invalidReported = false;
8688
this.compiler.hooks.watchRun.callAsync(this.compiler, err => {
8789
if (err) return this._done(err);
8890
const onCompiled = (err, compilation) => {
@@ -270,7 +272,10 @@ class Watching {
270272
this._onChange();
271273
},
272274
(fileName, changeTime) => {
273-
this.compiler.hooks.invalid.call(fileName, changeTime);
275+
if (!this._invalidReported) {
276+
this._invalidReported = true;
277+
this.compiler.hooks.invalid.call(fileName, changeTime);
278+
}
274279
this._onInvalid();
275280
}
276281
);
@@ -284,7 +289,8 @@ class Watching {
284289
if (callback) {
285290
this.callbacks.push(callback);
286291
}
287-
if (!this._initial) {
292+
if (!this._invalidReported) {
293+
this._invalidReported = true;
288294
this.compiler.hooks.invalid.call(null, Date.now());
289295
}
290296
this._invalidate();

test/MultiCompiler.test.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ describe("MultiCompiler", function () {
246246
};
247247
const events = [];
248248
compiler.compilers.forEach(c => {
249+
c.hooks.invalid.tap("test", () => {
250+
events.push(`${c.name} invalid`);
251+
});
249252
c.hooks.watchRun.tap("test", () => {
250253
events.push(`${c.name} run`);
251254
});
@@ -273,15 +276,15 @@ describe("MultiCompiler", function () {
273276
expect(compiler.compilers[0].modifiedFiles).toBe(undefined);
274277
expect(compiler.compilers[0].removedFiles).toBe(undefined);
275278
expect(events).toMatchInlineSnapshot(`
276-
Array [
277-
"b run",
278-
"b done",
279-
"c run",
280-
"c done",
281-
"a run",
282-
"a done",
283-
]
284-
`);
279+
Array [
280+
"b run",
281+
"b done",
282+
"c run",
283+
"c done",
284+
"a run",
285+
"a done",
286+
]
287+
`);
285288
events.length = 0;
286289
// wait until watching begins
287290
setTimeout(() => {
@@ -301,8 +304,10 @@ describe("MultiCompiler", function () {
301304
expect(compiler.compilers[1].removedFiles).toEqual(new Set());
302305
expect(events).toMatchInlineSnapshot(`
303306
Array [
307+
"b invalid",
304308
"b run",
305309
"b done",
310+
"a invalid",
306311
"a run",
307312
"a done",
308313
]
@@ -317,10 +322,13 @@ describe("MultiCompiler", function () {
317322
`);
318323
expect(events).toMatchInlineSnapshot(`
319324
Array [
325+
"b invalid",
320326
"b run",
321327
"b done",
328+
"a invalid",
322329
"a run",
323330
"a done",
331+
"a invalid",
324332
"a run",
325333
"a done",
326334
]
@@ -344,10 +352,13 @@ describe("MultiCompiler", function () {
344352
`);
345353
expect(events).toMatchInlineSnapshot(`
346354
Array [
355+
"b invalid",
356+
"c invalid",
347357
"b run",
348358
"b done",
349359
"c run",
350360
"c done",
361+
"a invalid",
351362
"a run",
352363
"a done",
353364
]

0 commit comments

Comments
 (0)