Skip to content

Commit

Permalink
fix(index): enable HMR in case locals (css-modules) are unchanged (
Browse files Browse the repository at this point in the history
  • Loading branch information
lydell authored and michael-ciniawsky committed Jan 26, 2018
1 parent 9b46128 commit 3a4cb53
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions index.js
Expand Up @@ -23,13 +23,22 @@ module.exports.pitch = function (request) {
"// Hot Module Replacement",
"if(module.hot) {",
" // When the styles change, update the <style> tags",
" if(!content.locals) {",
" module.hot.accept(" + loaderUtils.stringifyRequest(this, "!!" + request) + ", function() {",
" var newContent = require(" + loaderUtils.stringifyRequest(this, "!!" + request) + ");",
" if(typeof newContent === 'string') newContent = [[module.id, newContent, '']];",
" update(newContent);",
" });",
" }",
" module.hot.accept(" + loaderUtils.stringifyRequest(this, "!!" + request) + ", function() {",
" var newContent = require(" + loaderUtils.stringifyRequest(this, "!!" + request) + ");",
" if(typeof newContent === 'string') newContent = [[module.id, newContent, '']];",
" var locals = (function(a, b) {",
" var key, idx = 0;",
" for(key in a) {",
" if(!b || a[key] !== b[key]) return false;",
" idx++;",
" }",
" for(key in b) idx--;",
" return idx === 0;",
" }(content.locals, newContent.locals));",
" // This error is caught and not shown and causes a full reload.",

This comment has been minimized.

Copy link
@vegawong

vegawong May 14, 2018

it should show warning or auto reload page but not abort error

This comment has been minimized.

Copy link
@alexander-akait

alexander-akait May 14, 2018

Member

@vegawong please don't add you comments in PR that already merged, please create in issue, thanks!

" if(!locals) throw new Error('Aborting CSS HMR due to changed css-modules locals.');",
" update(newContent);",
" });",
" // When the module is disposed, remove the <style> tags",
" module.hot.dispose(function() { update(); });",
"}"
Expand Down

0 comments on commit 3a4cb53

Please sign in to comment.