-
Notifications
You must be signed in to change notification settings - Fork 43
Bugfix: watchRunHook race condition periodically breaks change detection triggered by writeModule (webpack@4) #82
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
Conversation
detection triggered by writeModule
@larixer 👍, this is my first foray into a webpack lifecycle. Just wanted to note that the timestamp discrepancy which causes missed rebuilds may ultimately come down to the fact that webpack-virtual-modules/src/index.ts Lines 170 to 171 in 6072912
modifies the From some debugging I noticed that these were not the same map... hence #66 being necessary to prevent every-module rebuilds on any change, but with it comes a need to alert webpack to the changes I could be off in my observations and/or there is possibly a better way to fix it but I am not familiar enough with webpack internals/conventions to propose anything in particular. Sidenote: I also found that changing the hook: webpack-virtual-modules/src/index.ts Line 275 in 6072912
To instead use something like |
Here's some observations too:
This led me here: https://github.com/webpack/webpack/blob/c572c15a413ef7d086b52ccc78d9512a192954d7/lib/Watching.js#L134 That was the only place where I wanted to get more info, so I put these right above L134.
And here's what I got:
1: Provided by webpack-virtual-modules/src/index.ts Lines 262 to 268 in 6072912
2: Provided by webpack-virtual-modules/src/index.ts Lines 170 to 171 in 6072912
Timestamps are created here: https://github.com/webpack/webpack/blob/c572c15a413ef7d086b52ccc78d9512a192954d7/lib/node/NodeWatchFileSystem.js#L54 Would be nice if I could reproduce 'it doesn't rebuild' behavior, or even better - make test for it... I tried to change hook as you said, tests passed. |
Hi there ! Thanks ! this PR helps me figure out why the hell my "virtual globe index files" weren't rebuilt during the hot update. In fact, for the same reasons i had the same problem while making my plugin compatible with webpack 5 ( layer-pack); The updated virtual files were not recompiled. I tried this fix, but Wp5 uses advanced method to do this TS test. It uses a concept of "snapshots" to have a better caching strategy I guess. I directly tap the closest hook I found; the compilation queue. It's probably not the best method i guess ( it test all the added modules ), but this one work in WP5 too. So for inspiration i wrote this, maybe it will help :)
|
Closing, as the PR is stale |
What's the problem this PR addresses?
Issue likely introduced by #66 whereby custom compiler hooks (eg
watchRun
,compilation
) which implement a dynamicwriteModule
call will periodically (~half the time in the case of mywatchRun
) fail to trigger a rebuild of the virtual module. For me this didn't affect production builds, but presented when using the webpack dev server.webpack-virtual-modules/src/index.ts
Line 266 in 6072912
Above line will preserve the virtualFile's mtime, which makes sense in preventing every change from rebuilding every module, but also prevents
writeModule
calls from correctly triggering the necessary rebuilds down the line.More specifically, the failure happens due to a check here:
https://github.com/webpack/webpack/blob/5d3004cccd3dd5af2721c39a7a8a27b12b3d0c19/lib/NormalModule.js#L533
Where
timestamp
is actually the last compilation's virtualFile's mtime.How did you fix it?
While not the ideal/perfect solution, this change forces an update to the
compiler.fileTimestamps
reference of avirtualModule
on whichwriteModule
was called. As I see it: if you callwriteModule
you necessarily are "touching" the file (updating mtime)