Repository navigation
Description
Do you want to request a feature or report a bug?
Report a bug, or maybe I'm using it wrong, at the least it's unexpected behavior and the documentation is missing.
What is the current behavior?
A module was cached when it should not have been cached.
If the current behavior is a bug, please provide the steps to reproduce.
I have a plugin that hooks into create-module of NormalModuleFactory, the result is a new raw module with the dependencies from a module of a parent compilation.
The code:
...
webCompiler.plugin('compilation', (webCompilation, { normalModuleFactory }) => {
normalModuleFactory.plugin('create-module', data => {
if (!data.resourceResolveData.path.endsWith('.js')) {
const parentCompilationModule = compilation.findModule(data.request)
if (parentCompilationModule) {
// mutation in webpack internals is a minefield, tread carefully
const dependencies = parentCompilationModule.dependencies.slice()
const parentSource = new ReplaceSource(parentCompilationModule.originalSource())
const { dependencyTemplates, outputOptions, moduleTemplate: { requestShortener } } = webCompilation
// from NormalModule.sourceDependency
dependencies.forEach(dependency => {
const template = dependencyTemplates.get(dependency.constructor)
if(!template) throw new Error('No template for dependency: ' + dependency.constructor.name)
template.apply(dependency, parentSource, outputOptions, requestShortener, dependencyTemplates)
})
const result = new RawModule(parentSource.source())
result.dependencies = dependencies
return result
}
}
})
})The module.unsafeCache option is by default true and setting it to false caused this code to be executed on every change.
What is the expected behavior?
I understand this use case is non-typical, but the cache is implemented in a very ad-hoc fashion by mutating the dependency:
// retrieval
const cacheEntry = dependencies[0].__NormalModuleFactoryCache
...
// setting
dependencies.forEach(d => d.__NormalModuleFactoryCache = module)
I would expect the module.unsafeCache to be false by default. Or, if it is true to be more sophisticated and not implemented by mutating all dependencies and grabbing the first dependency.
But, more importantly, have the documentation explain what module.unsafeCache does. I could for example provide a function that checks the module and test if it's one of these special ones. For now I have set it to false but since the documentation is missing I am not sure of the performance penalty.
If this is a feature request, what is motivation or use case for changing the behavior?
Not sure, I think it's mostly a bug report about missing documentation.
Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
None are relevant for this issue. The context in which we discovered the problems might be:
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
sokra commentedon Nov 30, 2017
A WeakMap would be better here. Send a PR if you like to.
FadySamirSadek commentedon Mar 24, 2018
@sokra I would love to take this one , but I need more details about the suggested solution as I do not have a clear understanding how it should be implemented.
webpack-bot commentedon Sep 22, 2018
This issue had no activity for at least half a year.
It's subject to automatic issue closing if there is no activity in the next 15 days.
EECOLOR commentedon Sep 22, 2018
@webpack-bot This issue is still relevant
sokra commentedon Sep 24, 2018
The mutating thing was fixed.
sokra commentedon Sep 24, 2018
@webpack-bot move to webpack/webpack.js.org
webpack-bot commentedon Sep 24, 2018
I've moved it to webpack/webpack.js.org.