Obscure Error at runtime - ASSERTION ERROR: Reached the max number of directives [Expected=> 1 != 1 <=Actual]
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
Observables that emit within the angular tick cycle can cause the component to crash.
What appears to be happening is that viewContainerRef.createEmbeddedView is recursively calling itself due to the observable emitting before it gets a chance to return.
This is a contrived example to get to an underlying issue that I've had using *ngrxLet.
Ngrx can probably fix their issue by not relying on createEmbeddedView returning. However, there are other cases where a developer may actually intend to call createEmbeddedView multiple times recursive or not.
I believe this is unexpected behavior, however if there's a reason it shouldn't be able to be called recursively a more helpful error message may be more helpful (pun) and some documentation on this limitation.
The workaround was to emit in a setTimeout or pipe(delay(0,asyncScheduler))
Please provide a link to a minimal reproduction of the bug
https://github.com/e-davidson/angular-issue-reproduction-2021
Please provide the exception or error you saw
ERROR Error: ASSERTION ERROR: Reached the max number of directives [Expected=> 1 != 1 <=Actual]
at throwError (core.mjs:326)
at assertNotEqual (core.mjs:282)
at initTNodeFlags (core.mjs:10443)
at resolveDirectives (core.mjs:10199)
at elementContainerStartFirstCreatePass (core.mjs:14972)
at Module.ɵɵelementContainerStart (core.mjs:15000)
at AppComponent_ng_container_0_Template (app.component.html:1)
at executeTemplate (core.mjs:9637)
at renderView (core.mjs:9440)
at TemplateRef.createEmbeddedView (core.mjs:23034)
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 13.0.3
Node: 14.17.0
Package Manager: npm 7.24.1
OS: linux x64
Angular: 13.0.2
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1300.3
@angular-devkit/build-angular 13.0.3
@angular-devkit/core 13.0.3
@angular-devkit/schematics 13.0.3
@angular/cli 13.0.3
@schematics/angular 13.0.3
rxjs 7.4.0
typescript 4.4.4
Anything else?
No response