Skip to content

Commit 3a4cb53

Browse files
lydellmichael-ciniawsky
authored andcommittedJan 26, 2018
fix(index): enable HMR in case locals (css-modules) are unchanged (#298)
1 parent 9b46128 commit 3a4cb53

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed
 

‎index.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,22 @@ module.exports.pitch = function (request) {
2323
"// Hot Module Replacement",
2424
"if(module.hot) {",
2525
" // When the styles change, update the <style> tags",
26-
" if(!content.locals) {",
27-
" module.hot.accept(" + loaderUtils.stringifyRequest(this, "!!" + request) + ", function() {",
28-
" var newContent = require(" + loaderUtils.stringifyRequest(this, "!!" + request) + ");",
29-
" if(typeof newContent === 'string') newContent = [[module.id, newContent, '']];",
30-
" update(newContent);",
31-
" });",
32-
" }",
26+
" module.hot.accept(" + loaderUtils.stringifyRequest(this, "!!" + request) + ", function() {",
27+
" var newContent = require(" + loaderUtils.stringifyRequest(this, "!!" + request) + ");",
28+
" if(typeof newContent === 'string') newContent = [[module.id, newContent, '']];",
29+
" var locals = (function(a, b) {",
30+
" var key, idx = 0;",
31+
" for(key in a) {",
32+
" if(!b || a[key] !== b[key]) return false;",
33+
" idx++;",
34+
" }",
35+
" for(key in b) idx--;",
36+
" return idx === 0;",
37+
" }(content.locals, newContent.locals));",
38+
" // This error is caught and not shown and causes a full reload.",
Has conversations. Original line has conversations.
39+
" if(!locals) throw new Error('Aborting CSS HMR due to changed css-modules locals.');",
40+
" update(newContent);",
41+
" });",
3342
" // When the module is disposed, remove the <style> tags",
3443
" module.hot.dispose(function() { update(); });",
3544
"}"

0 commit comments

Comments
 (0)
Please sign in to comment.