Skip to content

Commit 3a4cb53

Browse files
lydellmichael-ciniawsky
authored andcommitted
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

Lines changed: 16 additions & 7 deletions
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.",
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy