Skip to content

Commit 1726325

Browse files
committed
really fixed the bug
1 parent ac897a7 commit 1726325

File tree

3 files changed

+60
-9
lines changed

3 files changed

+60
-9
lines changed

lib/HotModuleReplacementPlugin.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,14 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
5454
if(!records) return;
5555
if(!records.hash) return;
5656
var preHash = records.preHash;
57-
if(!preHash) {
58-
records.preHash = this.hash;
59-
return;
60-
}
57+
if(!preHash) preHash = "x";
6158
if(preHash === this.hash) {
62-
if(records.prepreHash)
63-
this.modifyHash(records.prepreHash);
59+
this.modifyHash(records.prepreHash);
6460
return;
6561
}
66-
records.prepreHash = preHash;
62+
records.prepreHash = records.hash || "x";
6763
records.preHash = this.hash;
68-
this.modifyHash(preHash);
64+
this.modifyHash(records.prepreHash);
6965
});
7066
compilation.plugin("additional-chunk-assets", function() {
7167
var records = this.records;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack",
3-
"version": "0.11.0-beta10",
3+
"version": "0.11.0-beta11",
44
"author": "Tobias Koppers @sokra",
55
"description": "Packs CommonJs/AMD/Labeled Modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jade, coffee, css, less, ... and your custom stuff.",
66
"dependencies": {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
var should = require("should");
2+
var path = require("path");
3+
var fs = require("fs");
4+
5+
var webpack = require("../");
6+
7+
describe("HotModuleReplacementPlugin", function() {
8+
it("should not have circular hashes but equal if unmodified", function(done) {
9+
var entryFile = path.join(__dirname, "js", "entry.js");
10+
var recordsFile = path.join(__dirname, "js", "records.json");
11+
try { fs.unlinkFileSync(recordsFile); } catch(e) {}
12+
var compiler = webpack({
13+
entry: entryFile,
14+
recordsPath: recordsFile,
15+
output: {
16+
path: path.join(__dirname, "js")
17+
},
18+
hot: true
19+
});
20+
fs.writeFileSync(entryFile, "1", "utf-8");
21+
compiler.run(function(err, stats) {
22+
if(err) throw err;
23+
var oldHash1 = stats.toJson().hash;
24+
compiler.run(function(err, stats) {
25+
if(err) throw err;
26+
var lastHash1 = stats.toJson().hash;
27+
lastHash1.should.be.eql(oldHash1);
28+
fs.writeFileSync(entryFile, "2", "utf-8");
29+
compiler.run(function(err, stats) {
30+
if(err) throw err;
31+
var lastHash2 = stats.toJson().hash;
32+
fs.writeFileSync(entryFile, "1", "utf-8");
33+
compiler.run(function(err, stats) {
34+
if(err) throw err;
35+
var currentHash1 = stats.toJson().hash;
36+
currentHash1.should.not.be.eql(lastHash1);
37+
fs.writeFileSync(entryFile, "2", "utf-8");
38+
compiler.run(function(err, stats) {
39+
if(err) throw err;
40+
var currentHash2 = stats.toJson().hash;
41+
compiler.run(function(err, stats) {
42+
if(err) throw err;
43+
stats.toJson().hash.should.be.eql(currentHash2);
44+
currentHash2.should.not.be.eql(lastHash2);
45+
currentHash1.should.not.be.eql(currentHash2);
46+
lastHash1.should.not.be.eql(lastHash2);
47+
done();
48+
});
49+
});
50+
});
51+
});
52+
});
53+
});
54+
});
55+
});

0 commit comments

Comments
 (0)