Skip to content

Commit

Permalink
fix: perform a HMR update after inserting a new CSS module
Browse files Browse the repository at this point in the history
Fixes #706
  • Loading branch information
latin-1 committed Feb 5, 2023
1 parent 38fcf7d commit 3ddfe0e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/hmr/hotModuleReplacement.js
Expand Up @@ -246,6 +246,8 @@ function isUrlRequest(url) {
return true;
}

const updateFunctionMap = Object.create(null);

/**
* @param {TODO} moduleId
* @param {TODO} options
Expand All @@ -258,6 +260,11 @@ module.exports = function (moduleId, options) {
return noop;
}

const key = JSON.stringify({ moduleId, options });
if (updateFunctionMap[key]) {
return updateFunctionMap[key];
}

const getScriptSrc = getCurrentScriptUrl(moduleId);

function update() {
Expand All @@ -281,5 +288,6 @@ module.exports = function (moduleId, options) {
}
}

return debounce(update, 50);
updateFunctionMap[key] = debounce(update, 50);
return updateFunctionMap[key];
};
3 changes: 3 additions & 0 deletions src/loader.js
Expand Up @@ -60,6 +60,9 @@ function hotLoader(content, context) {
})});
module.hot.dispose(cssReload);
${accept}
if (module.hot.status() !== "idle") {
cssReload();
}
}
`;
}
Expand Down

0 comments on commit 3ddfe0e

Please sign in to comment.