-
-
Notifications
You must be signed in to change notification settings - Fork 380
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: Clear correct cache when compiling with Webpack #838
Conversation
Sorry, took some time to connect all the dots and pieces and understand how it's working, or how it's not working :) You are absolutely correct, |
packages/server/src/util.js
Outdated
@@ -1,5 +1,6 @@ | |||
export const clearModuleCache = moduleName => { | |||
const m = require.cache[moduleName] | |||
const cache = (typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : require).cache; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for being picky, but let's safe future developers time and make it right this time
Let's use "single source" for both operations if the HAVE to be synchronized.
const getRequire = () => typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : require;
export const clearModuleCache = moduleName => {
const cache = getRequire().cache; // 👈
...
}
export const smartRequire = modulePath => {
if (process.env.NODE_ENV !== 'production' && module.hot) {
clearModuleCache(modulePath)
}
return getRequire(moduleName); // 👈
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach is correct. Let's make it ideal
6ede109
to
73f784e
Compare
@theKashey OK, no problem. I've refactored it based on your suggestions and kept |
thank you for your contribution, I will release the update shortly. |
Hi! When will it be released? |
Would appreciate a release with this commit when possible 🙏 |
🦗 |
🙄😅 |
Summary
Using
module.hot
is forcing me to use WebpackHotModuleReplacementPlugin
and excluding@loadable/server
fromnodeExternal()
so thatmodule.hot
is present. (8f10896)Then
__non_webpack_require__
is used insmartRequire
(https://github.com/gregberge/loadable-components/blob/main/packages/server/src/util.js#L30) butclearModuleCache
is clearing cache fromrequire
not from__non_webpack_require__
.This PR should fix this problem.
Test plan
See #821