-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Browser reloads infinitely when using multi-compiler mode #3803
Comments
Most likely problem in |
Okay thanks, I was on the edge to post it there instead, but the HMR message brought me here. I'll try my luck over there! |
Oh, found a problem |
You can't run multiple dev server on multiple compiler with |
Problem due HMR logic, we track hash of build but you have two builds, so hash changed when you change something in your another build |
Why do you need one dev server on multiple compilers, it is like independent builds in your case, so should be handled independent servers |
Some of my entry points just need to be handled differently (different output options). But for those I don't need another webserver. Is this not a valid use case? For example, some of my files are libraries, and the main entry point is not. |
In this case you should use |
This error also seems to surface if you have an isomorphic setup with both a |
Can you provide example? It should work |
@alexander-akait ill make a simpler reproduction, but if you want to test quickly our Marko webpack example repo has this issue.
I’ll be downgrading this example today, and I’ll also create a more simplified reproduction. Will share once I have |
without
|
Sorry, replying with code snippets via mobile is hard -_-. I updated the previous comment with the correct command. |
@alexander-akait here is a more simplified reproduction: https://github.com/DylanPiercey/webpack-dev-server-issue-infinite-reload |
I will try to fix multi compiler issues on the next week, also try to add support for multiple dev servers, a lot of tasks, sorry for delay |
For me: add test and example for #3836 and for #3831 (https://github.com/koggdal/webpack-dev-server-issue-3831-demo) |
Note for everyone: Three solutions for multi compiler mode:
|
Thank you @alexander-akait! 🙏 On the "migrate on multi entries configuration" point, what does this refer to? |
@koggdal found solution for your case, regarding migrate on multi entries configuration https://webpack.js.org/concepts/entry-points/#object-syntax |
PR: #3840, I am checking it on all reported repos and when add tests cases and do release |
@alexander-akait I think what makes that tricky for us is that the different apps require slight tweaks to the Webpack config (one app might need one more plugin, or different apps need different instances of a plugin with different parameters). But if the multiple web targets support is coming soon, and that works for us (with dependencies set), that would be great! 👍 |
@chmanie PR above fix your problem too, one note - if you want to use each build from the each compilation on the same page you need to use module.exports = [
{
name: 'one',
mode: 'development',
entry: './temp2.js',
output: {
uniqueName: 'one',
filename: 'main2.js',
path: path.resolve(__dirname, 'dist'),
},
},
{
name: 'two',
mode: 'development',
entry: './temp.js',
output: {
uniqueName: 'two',
filename: 'main1.js',
path: path.resolve(__dirname, 'dist'),
},
},
]; Why? Because we have global HMR function, and if you not set different name, they will be override each, i.e. last HMR function override first and HMR will be broken, different names give different names for HMR function and allow to use different configurations on the same page |
Found another problem, but it will be fixed late (today/tomorrow) |
@alexander-akait I don't believe that #3840 or any of your recommendations above would solve the issue of isomorphic apps that have a server and browser compiler. Is there a plan to support that kind of setup? FWIW Ideally any build to a server compiler would trigger a live reload to the browser unless every module changed could hot reload in the browser compiler. Currently with webpack-dev-server@3 I don't believe it works that way, but instead just does a full page reload whenever either compiler changes (which is what was broken in webpack-dev-server@4). |
@DylanPiercey this is another problem, albeit close to what I wrote here, there are two issues:
|
@DylanPiercey also do you use https://webpack.js.org/configuration/other-options/#dependencies? Otherwise server and client don't known about yourselves |
@DylanPiercey I want to clarify that the only problem is the lack of live reload, right? |
@alexander-akait that's correct yes |
After making the changes you had in #3840 it does not appear to infinite loop, but simply doesn't trigger the live reload. |
Yes, because there are two different problems, currently I fix infinity loop, becaue it happens not only for your case, the second PR will fix reload logic for your case |
Awesome, looking forward to it! Thanks for looking into this 🙏 |
Happy to test out whatever change locally if helpful, just @ me 😄 |
@alexander-akait was just playing around with this a little bit, very possible I'm going in the wrong direction. But it seems in my case the issue is due to I was able to get things working by changing that code to be var isInitial = status.previousHash === webpackHash; Which I think makes sense, but not totally sure. Another (very minor) issue I see with https://github.com/webpack/webpack-dev-server/pull/3840/files?file-filters%5B%5D=.js&hide-deleted-files=true#diff-b706bbadb3d2315d99678f05e1f4bfd78a4bb4a7a6c65f3e81f1386fee3c883aR1153 is that the setupHooks() {
let pending = true;
this.compiler.hooks.invalid.tap("webpack-dev-server", () => {
if (!pending && this.webSocketServer) {
pending = true;
this.sendMessage(this.webSocketServer.clients, "invalid");
}
});
this.compiler.hooks.done.tap("webpack-dev-server", (stats) => {
if (this.webSocketServer) {
this.sendStats(this.webSocketServer.clients, this.getStats(stats));
}
this.stats = stats;
pending = false;
}); |
Whoops, forgot to mention I also added status.previousHash = status.currentHash; Before this line: https://github.com/webpack/webpack-dev-server/blob/master/client-src/index.js#L90 |
@DylanPiercey |
If you have multiple indented builds, for example you have |
@alexander-akait that's not true. With the multi compiler |
But if you change something in one of the configuration why we should wait? If builds will be long you will not get infromation about changes, i.e. logging |
@alexander-akait I'm not following? The multi compiler With what I had above it'd notify the browser that a build is happening only when the first compiler goes invalid. Right now it notifies the browser multiple times for the same build. I believe even with the |
You can run invalidate without finish build and no logs in your case, multiple |
Are you saying the |
Yes |
What is the problem with multiple |
We can fix it just adding |
Found a problem, why we do not reload, WIP, maybe do release today |
@DylanPiercey I got your idea, because it is valid solution, try #3841, I will test it with lazyCompilation and if all will be good, add more tests and do release |
@alexander-akait with both #3840 and #3841 it seems all is working! |
I will add more tests and will merge |
@alexander-akait Sorry for not getting back earlier! I've tested both your changes (together with setting up However, I get a single "Disconnected" on load, and then it reconnects and then it's fine. The test repo I made for you doesn't seem to have that issue, so something must be different in our project setup. It's really late here now, and I'm likely pretty busy tomorrow, but I will try to see if I can understand what's different in our setup. |
@koggdal I think this problem in other place, please open an new issue tomorrow with example, logic for hot/reload not connected in any way with |
Note - |
@alexander-akait can confirm it's working with the new release. Thanks for getting this out so fast and for the support! |
Code
See full example repository for reproduction here
Please paste the results of
npx webpack-cli info
here, and mention other relevant informationExpected Behavior
I'm expecting the page not to reload infinitely. If my configuration is not correct, I would like for webpack to tell me that in some way.
Actual Behavior
The page reloads in an infinite loop. I could extract the console output from Firefox. The following output is the only output in the console and happens before the reload is triggered:
Important
It is important to note that this behaviour is not triggered in 100% of the cases. For me it roughly triggers in 1/3 of the cases, when using a more complex configuration (in the project I encountered this in), it's almost every time).
For Bugs; How can we reproduce the behavior?
Please see https://github.com/chmanie/webpack-hmr-bug to find information on how to reproduce the bug (it's quite easy).
For Features; What is the motivation and/or use-case for the feature?
The text was updated successfully, but these errors were encountered: