hmr causes element disappear · Issue #59582 · angular/angular · GitHub
Skip to content

hmr causes element disappear #59582

Open
Open

Description

@jusfeel

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

No

Description

After upgrading to 19.1, template change keeps causing strange behaviors:

  • binding stops until I resize the browser window (variable binding with checkbox on the page for example)
  • my change simply does not appear not even a total page reload until I restart ng server
  • element disappear after any change happening on template ex. a nested component inside the template just disappears after I made tiny change on the template to trigger a hmr

I had to use no-hmr ng server --no-hmr to avoid this from happening.

So, it seems it's related to hmr.

Binding failure appears quite often on wsl2 but not appearing on Ubuntu 24 machine.

The element disappearing happens on both wsl2 and Linux.

Distributor ID: Ubuntu
Description:    Ubuntu 24.04.1 LTS
Release:        24.04
Codename:       noble
Angular CLI: 19.1.0
Node: 22.12.0
Package Manager: npm 10.9.0
OS: linux x64

Angular: 19.1.0
... animations, cli, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic
... platform-server, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1900.7
@angular-devkit/build-angular   19.1.0
@angular-devkit/core            19.1.0 (cli-only)
@angular-devkit/schematics      19.1.0
@angular/cdk                    19.0.5
@schematics/angular             19.1.0
rxjs                            7.8.1
typescript                      5.6.3
zone.js                         0.15.0

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw


Please provide the environment you discovered this bug in (run ng version)


Anything else?

No response

Activity

  1. added this to the needsTriage milestone on Jan 17, 2025
  2. crisbeto commented on Jan 17, 2025

    @crisbeto
    Member

    Can you try updating to 19.1.1? I suspect this is related to #59562.

  3. emnljs commented on Jan 17, 2025

    @emnljs

    i am having the same issue with 19.1.1 using ionic angular

  4. dw-0 commented on Jan 17, 2025

    @dw-0

    @crisbeto I am having this issue with 19.1.1 still as well. Im not sure which info to provide that could help you. In my case im using an nx workspace. Disabling hmr solves the issue. Having hmr enabled, pretty much any change in a template or typescript file causes elements or styles to disappear or lazy loading not working, hence breaking navigation of my page. If you need any more specific info, please let me know and i try to provide it.

  5. crisbeto commented on Jan 17, 2025

    @crisbeto
    Member

    It's hard to say what could causing it without looking at the code. Have you noticed this only in a specific component or everywhere. For reference, I'm thinking this might be the same root cause as #59559 and there the issue was visible also on a simplified component.

  6. dw-0 commented on Jan 17, 2025

    @dw-0

    In my case i first noticed it on a Syncfusion DataGrid component of medium complexity. After the first code change buttons and some styles of the table disappeared. Im not allowed to share the code due to company policies but it may be sufficient to grab the example code of the first example from here: https://helpej2.syncfusion.com/angular/documentation/grid/tool-bar/tool-bar-items?cs-save-lang=1&cs-lang=ts

    For example, i have a search field on my tables as well, and that was one of the elements that disappeard together with all other buttons of the toolbar element of that datagrid after i changed the header text of a column for example and hmr was triggered.

  7. crisbeto commented on Jan 17, 2025

    @crisbeto
    Member

    Do you happen to be using the BrowserAnimationsModule in your app?

  8. dw-0 commented on Jan 17, 2025

    @dw-0

    @crisbeto Yes, i do.

  9. crisbeto commented on Jan 17, 2025

    @crisbeto
    Member

    It's possible you may be hitting the issue fixed in #59574. Might be worth trying to replace BrowserAnimationsModule with NoopAnimationsModule just to see if the issue goes away.

  10. dw-0 commented on Jan 17, 2025

    @dw-0

    I switched from BrowserAnimationsModule to NoopAnimationsModule as suggested, but i still face that issue.

  11. jusfeel commented on Jan 18, 2025

    @jusfeel
    Author

    After upgrading, all seem fixed on my Angular app on wsl2. (Not ionic Angular)

    Angular CLI: 19.1.2
    Node: 22.12.0
    Package Manager: npm 10.9.0
    OS: linux x64
    
    Angular: 19.1.1
    ... animations, common, compiler, compiler-cli, core, forms
    ... localize, platform-browser, platform-browser-dynamic
    ... platform-server, router
    
    Package                         Version
    ---------------------------------------------------------
    @angular-devkit/architect       0.1900.7
    @angular-devkit/build-angular   19.1.2
    @angular-devkit/core            19.1.2 (cli-only)
    @angular-devkit/schematics      19.1.2
    @angular/cdk                    19.1.0
    @angular/cli                    19.1.2
    @schematics/angular             19.1.2
    rxjs                            7.8.1
    typescript                      5.6.3
    zone.js                         0.15.0
    
  12. crisbeto commented on Jan 20, 2025

    @crisbeto
    Member

    We've released versions 19.1.2 of the framework and 19.1.3 of the CLI which include some HMR fixes. Does it resolve this issue?

  13. hasokeric commented on Jan 20, 2025

    @hasokeric

    I wonder if this is related to #59632 because I have a component that has a global .scss and also it uses styles with :host inside the .component.ts and with HMR somehow the styles in the component, break. In addition I use tailwind css mixed with it.

    --no-hmr

    Image

    With HMR

    Image

    Notes

    This one is basically one of those ngProjectAs custom slot components.

    <div class="absolute inset-0 flex h-full min-w-0 flex-col">
      <div class="flex h-full flex-auto">
        <wap-dock-manager [layout]="layout" class="h-full flex-auto">
          <div #contentSlot slot="content1" class="wap-dock-content h-1/2">Content 1</div>
          <div #contentSlot slot="unpinned1" class="wap-dock-content h-50">Unpinned Pane 1</div>
          <div #contentSlot slot="document1" class="wap-dock-content">Document 1</div>
          <div #contentSlot slot="document2" class="wap-dock-content">Document 2</div>
          <div #contentSlot slot="tab1" class="wap-dock-content">Tab 1</div>
          <div #contentSlot slot="tab2" class="wap-dock-content">Tab 2</div>
          <div #contentSlot slot="tab3" class="wap-dock-content">Tab 3</div>
          <div #contentSlot slot="tab4" class="wap-dock-content">Tab 4</div>
          <div #contentSlot slot="tab5" class="wap-dock-content">Tab 5</div>
          <div #contentSlot slot="content2" class="wap-dock-content">Content 2</div>
          <div #contentSlot slot="floating" class="wap-dock-content">Floating Content</div>
        </wap-dock-manager>
      </div>
    </div>
    • It does use :host and :host-context but even with that removed, no change.
  14. dw-0 commented on Jan 21, 2025

    @dw-0

    We've released versions 19.1.2 of the framework and 19.1.3 of the CLI which include some HMR fixes. Does it resolve this issue?

    @crisbeto i updated to the following versions:

    "@angular-devkit/build-angular": "19.1.3",
    "@angular-devkit/core": "19.1.3",
    "@angular-devkit/schematics": "19.1.3",
    "@angular/cli": "19.1.3",
    

    In my case, this did sadly not solve the issue.

  15. cagataycivici commented on Jan 21, 2025

    @cagataycivici

    Still broken, PrimeNG development is halted now due to this.

  16. hasokeric commented on Jan 21, 2025

    @hasokeric

    @crisbeto will PR #59644 fix this one as well?

  17. crisbeto commented on Jan 21, 2025

    @crisbeto
    Member

    It's unclear since we don't have a way to reproduce this.

  18. hasokeric commented on Jan 21, 2025

    @hasokeric

    ok I will wait for the PR and try again, if not I can make a small ngProjectAs example with a mixed global .scss, a style in the component what not.

  19. msmallest commented on Jan 21, 2025

    @msmallest
    Contributor

    @hasokeric the second and third points of the body of this issue I have experienced myself. For my own code where I observed this, they are addressed as of the PR. I also tested the reproduction you liked in the self-referencing 59632 issue and the PR changes fixed that repro as well.

    If you want to test the PR yourself, I learned how to do it recently and it is kind of fun. It's basically just grabbing the node_modules/@angular subfolders from the PR and dropping them in.

    1. Visit the GH actions for the build of the PR. Here is a link to the latest build that I verified these changes on: link.
    2. Open "Archive Build Artifacts" step
    3. Download the artifact from line 20. Will start downloading on click of the url.
    4. Unzip and drop those into node_modules/@angular and say yes to all of the replace folder prompts.
    5. Now you have the latest Angular builds from that PR - serve with HMR to try yourself

    I just did that for 59632/59639/59640 addressed in the PR and they were fixed by these changes in my respective repos.

  20. hasokeric commented on Jan 22, 2025

    @hasokeric

    @crisbeto , I tested the PR #59644 based on @msmallest suggestion, and it appears to have resolved issues in:

    • Complex components
    • Nested components
    • Sub-components
    • Dynamic components
    • Components combining SCSS and Tailwind
    • Global SCSS
    • Components with ViewEncapsulation.None
    • Etc.

    Great Work!

    Result

    Image

  21. hasokeric commented on Jan 22, 2025

    @hasokeric

    The only thing that I need to figure out is how to get HMR to not destroy stuff that you grab from a child and move into a parent container, since it doesnt re-run AfterViewInit, probably need to look at different lifecycle hooks.

    But thats probably my lack of Angular Skill here making a Dialog Wrapper. Might just be a ElementRef vs ContentChild battle.

    What happens if I modify my dialog.component.scss the dynamically added content created via this._actionsContainer.nativeElement.appendChild(customActions); disappears

  22. canberkardic commented on Jan 23, 2025

    @canberkardic

    Also I belive it affetcs the bundled & deployed application lifecycle.
    In below when I first land into my project's landing page it's like that

    PS : We're using a custom web component library

    Image

    Whenever I reload the page it works as expected

    Image
  23. hasokeric commented on Jan 23, 2025

    @hasokeric

    I am not sure if thats a limitation of it, or considered a bug. Should HMR be removing dynamically created DOM elements. @crisbeto thats the only thing I really have left as a HMR nusance.

    Like if I add a <p>Test</p> using nativeElement and add it to a <div> during runtime. After making a scss or html change the inserted <p>Test</p> would disappear.

    Which is fine, but might as well then reload the entire component, than to have it in a broken state, still reloading the component completely is still faster than full page reload.

  24. msmallest commented on Jan 23, 2025

    @msmallest
    Contributor

    @canberkardic can you provide a minimal reproduction of this web component issue? I wouldn't think that these changes would impact anything beyond serving locally with HMR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions