-
Notifications
You must be signed in to change notification settings - Fork 12k
ng serve --hmr
should apply changes in component styles without reinitialization of the whole app
#19867
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
Comments
I did look into a way to achieve this in the past. This is a non-trivial problem to solve, I will do some investigation but i think the the Framework needs to provide an API. See: angular/angular#39367 |
One addition: it's not only about the styles. |
I am very helpless, which means that Angular is not suitable for building large applications |
I am also a bit flummoxed, how hot reloading is still a problem for Angular. Current solution seems very heavy handed, as it reloads whole module. For single-module applications, or applications with bigger modules, that does almost nothing. |
Any hopes that this will be addressed any time soon? |
Any updates on this important issue? |
i just saw this post, wish i saw it earlier. onNgInit being initialized each time using hmr. thus ajax service function inside onNgInit being called. and i lose data. |
In all fairness, this is actually expected, the framework needs to instantiate the component again, because its internal code could change (i.e. things added to ngOnInit). Not sure why you would lose data, if you're actually calling for them during ngOnInit. |
Yes, the component re-intialization is fine. Actually @ronen009 the fact that you do an HTTP call inside of your component is a sign of bad architecture: the component should be "thin" and care only about the UI logic. |
Btw here's my workaround for now, guys: I use Nrwl Nx with Storybook, and HMR for Storybook works just perfectly! Because it has it's own Webpack configuration. Just try it out it's amazing! If I change CSS, it reloads only CSS portion. Same goes for HTML and TS. |
The call has to originate from somewhere, though, even if its implementation is abstracted into a separate service. Memoizing the result and adding your own HMR-related code just to "make it snappier" seems like a completely wrong way to go to me. There should be no HMR-related code at all. In such cases, there's just simply no way of overcoming this. If you change something in a component that initiates a call, every reload would cause that call to happen. That's ok, it's just a consequence of what this particular component does. On a component-level this is acceptable. What is not acceptable is that it goes for the whole module every time. |
@sebastian-zarzycki-es Well in my (large) project, I have a whole "dev cache" made with HTTP interceptor, that caches all the responses in a local DB (stripped out in prod build). + I made a Devtools panel to control that. When your HTTP request takes seconds, and when you have tons of HTTP requests per module, tricks to "make it snappier" start to make sense. I totally get your point tho |
I would argue that if you need many costly calls to reload a single page, then it's a sign that something should be redesigned there. But, yeah, it's IT, corner cases happen all the time. It can be helpful for a specific situation like yours, but it shouldn't be a prerequisite for HMR to work efficiently, as other technologies show us that it is entirely possible for HMR to work way way better. |
🤝 To sum up, it's an expected behavior, it's OK, and it's not related to this current issue. |
Let's keep tracking this issue here angular/angular#39367 since this is not possible without changes in the framework. Please thumbs up the mentioned issue, if you'd like this feature to be added. |
@alan-agius4 It's NOT related to CSS only (read this thread please). |
Any changes to a component or module at the moment will need a full application re-initialization. As per angular/angular#39367 (comment) without an API from the framework we cannot patch updates to component templates, styles and so on… and hence the why we are tracking this issue in angular/angular#39367 |
This framework is being rewritten and then rewritten and then rewritten again ad nauseam, while important development features like this linger for, apparently, 5 years. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🚀 Feature request
Command (mark with an
x
)Description
Currently during
ng serve --hmr
any change in component styles triggers reinitialization of the whole app. This behavior is far from ideal as route components in most of the apps need to load data asynchronously and their reinitialization triggers this process again, so applying a change in component's styles can't be reviewed immediately (as it should and as it's done in other frameworks like Vue or React).I've created a reproduction repo:
npm ci && npm start
and openlocalhost:4200
Initializing page...
and thenPage ready
.TestPageComponent
simulates data loading in it'sngOnInit
method.background-color: blue
.TestPageComponent
will be reinitialized and you'll be able to review the change only after 3 seconds.Describe the solution you'd like
I expect changes in component styles to be applied immediately without reinitialization of the host component.
By the way, changes in global styles are applied immediately, as they should.
The text was updated successfully, but these errors were encountered: