JavaScriptServices icon indicating copy to clipboard operation
JavaScriptServices copied to clipboard

HMR broken using Angular 2.4

Open ManuelDeLeon opened this issue 9 years ago • 8 comments

Create a new Angular project with the experimental patch (v0.8.1). The app runs fine the first time but if you update a file (say home.component.html) the browser goes blank and you see a bunch of errors in the console:

EXCEPTION: Error in :0:0 caused by: The selector "app" did not match any elements

ManuelDeLeon avatar Feb 03 '17 22:02 ManuelDeLeon

Did you rename the root component from <app>? Check your Views/Home/index.cshtml, and also what your app.component.ts selector is. Wasn't able to reproduce this one locally.

MarkPieszak avatar Feb 03 '17 22:02 MarkPieszak

Nope.

This generator can also be run with: yo aspnetcore-spa


     _-----_     ╭──────────────────────────╮
    |       |    │  Welcome to the ASP.NET  │
    |--(o)--|    │   Core Single-Page App   │
   `---------´   │        generator!        │
    ( _´U`_ )    │                          │
    /___A___\   /│      Version: 0.8.1      │
     |  ~  |     ╰──────────────────────────╯
   __'.___.'__
 ´   `  |° ´ Y `

? Framework Angular 2.4.5 (experimental)
? What type of project do you want to create? project.json (compatible with .NET Core tooling preview 2 and Visual Studio 20
15)
? Do you want to include unit tests? Yes

Ran: cross-env ASPNETCORE_ENVIRONMENT=Development dotnet run Then changed home.component.html header to: <h1>Hello, world! XXX</h1> Save => blank screen with error.

ManuelDeLeon avatar Feb 03 '17 22:02 ManuelDeLeon

When HMR updates modules, it detaches and reattaches changed components. DomRenderer.prototype.detachView removes all component elements which have parentNode defined (for app element it will be body element). As a temporary bypass I use ngOnDestroy(): void { document.body.appendChild(document.createElement("app")); }

nikitadmitry avatar Feb 04 '17 19:02 nikitadmitry

I also am seeing this. Thank you @nikitadmitry - I added that line in the ctor of app.component and this has helped resolve the issue for me also.

I also have not changed the default name app as the selector.

btmadison avatar Feb 06 '17 15:02 btmadison

@nikitadmitry Thank you for the interim fix - I'm back in business over here as well

chrisjmccrum avatar Feb 06 '17 18:02 chrisjmccrum

For me HMR broke with angular 2.4.6. We reverted back to 2.4.5 and it works.

hheexx avatar Feb 06 '17 20:02 hheexx

Thanks for the report. I've published generator-aspnetcore-spa 0.8.2 which pins to Angular 2.4.5. I'll look at relaxing this versioning restriction when I get a chance to investigate the issue with 2.4.6.

SteveSandersonMS avatar Feb 07 '17 19:02 SteveSandersonMS

The template is now updated to support HMR with newer Angular 2.x (tested with 2.4.7).

SteveSandersonMS avatar Feb 09 '17 15:02 SteveSandersonMS