angular: [elements]: custom element inside a custom element's template throw on destruction

I’m submitting a…


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

Current behavior

We have 3 custom elements, A , B and C - All are angular components converted to custom elements.

We create a new A programatically, with an injector.

Inside A we append HTML code, the code includes markup that will create B. (B doesn’t have an injector).

In B’s template, we have markup to create C.


Stopping here to point out that while C is inside an angular template markup and it is an angular component, the fact that it’s declared as a custom element means that it will be handled by @angular/elements.


Now, A was created programatically so we have a reference for it.
We remove it (NgElement.remove()) which starts the destruction process.

When @angular/elements starts the destruction process and error is thrown:

ERROR TypeError: Cannot read property ‘nativeNode’ of null

at removeDebugNodeFromIndex (core.js:5407) at DebugRenderer2.push.../../node_modules/@angular/core/fesm5/core.js.DebugRenderer2.destroyNode (core.js:11398) at destroyViewNodes (core.js:10613) at destroyView (core.js:10601) at callWithDebugContext (core.js:11351) at Object.debugDestroyView [as destroyView] (core.js:11035) at ViewRef_.push.../../node_modules/@angular/core/fesm5/core.js.ViewRef_.destroy (core.js:8868) at ComponentRef_.push.../../node_modules/@angular/core/fesm5/core.js.ComponentRef_.destroy (core.js:8705) at elements.js:236 at ZoneDelegate.push.../../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)

The error happens when @anguar/core try’s to destory C.

What happens is that DebugRenderer2.destroyNode() is called TWICE for C. My guess is that because C is a custom element used inside an angular template both angular and angular/elements invoke a destroy… something like that I guess.

Expected behavior

Should not throw…

It’s worth noting that even if I disable the delay of destruction it stlll throws

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 23
  • Comments: 15 (4 by maintainers)

Most upvoted comments

I believe this PR would fix this issue: https://github.com/angular/angular/pull/27631

If any body does please let me know, this is a big problem for me at the moment.

I believe this PR would fix this issue: #27631

Really hoping that it can be approved very soon. It looks like it just needs an approval to be merged right?

Any progress on this issue? I’m in the same boat.

@gkalpak I had the same issue, but I noticed, that the problem has been solved after recompiling dependencies (triggered by adding "postinstall": "ngcc" in package.json file).

Any way the recompilation broke us a different thing, but it’s not related to the topic.

Does anyone have any way to fix this? Or are we still waiting for a PR to be merged?