You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which @angular/* package(s) are the source of the bug?
Don't known / other
Is this a regression?
Yes
Description
In Hybrid Rendering, the AppEngine performs a route discovery run of the application to locate routes. During this run, environment initializers defined at the route level are skipped:
Hi @alan-agius4 thanks for the feedback. The workaround to angular/angular#51532 is to use a route level environment initializer to get the injector instance, so that loadChildren can be wrapped to run in a injection context:
/** * Workaround to emulate an injection context in the route's loadChildren resolver. * @param route * @returns * @see https://github.com/angular/angular/issues/51532#issuecomment-1956138610 */exportfunctionsetupInjectionContextForLoadChildren(route: Route): Route{letinjector: Injector|undefined=undefined;constinjectorInitializerProvider: Provider={provide: ENVIRONMENT_INITIALIZER,multi: true,useFactory:
(instance=inject(Injector))=>()=>{injector=instance;},};consttransformRoute=(child: Route)=>{if(!child.loadChildren)returnchild;constloadChildren=child.loadChildren;child.loadChildren=(...args)=>{if(!injector)thrownewError('Missing injector');returnrunInInjectionContext(injector,()=>loadChildren(...args));};returnchild;};return{path: '',providers: [injectorInitializerProvider],children: [transformRoute(route)],};}
Which @angular/* package(s) are the source of the bug?
Don't known / other
Is this a regression?
Yes
Description
In Hybrid Rendering, the AppEngine performs a route discovery run of the application to locate routes. During this run, environment initializers defined at the route level are skipped:
When running
ng serve
:It's easy to notice the route-level environment initializer only run once: it did not run during route discovery.
Please provide a link to a minimal reproduction of the bug
https://github.com/Char2sGu/issue-missing-env-init
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run
ng version
)Anything else?
No response
The text was updated successfully, but these errors were encountered: