Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: perform a HMR update after inserting a new CSS module #1006

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
13 changes: 12 additions & 1 deletion test/cases/hmr/expected/main.js
Expand Up @@ -255,6 +255,8 @@ function isUrlRequest(url) {
return true;
}

const updateFunctionMap = Object.create(null);

/**
* @param {TODO} moduleId
* @param {TODO} options
Expand All @@ -267,6 +269,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 @@ -290,7 +297,8 @@ module.exports = function (moduleId, options) {
}
}

return debounce(update, 50);
updateFunctionMap[key] = debounce(update, 50);
return updateFunctionMap[key];
};


Expand Down Expand Up @@ -367,6 +375,9 @@ __webpack_require__.r(__webpack_exports__);
var cssReload = __webpack_require__(/*! ../../../src/hmr/hotModuleReplacement.js */ "../../../src/hmr/hotModuleReplacement.js")(module.id, {"locals":false});
module.hot.dispose(cssReload);
module.hot.accept(undefined, cssReload);
if (module.hot.status() !== "idle") {
cssReload();
}
}


Expand Down