fix: don't instantiate providers with ngOnDestroy eagerly. (#15070)
BREAKING CHANGE: Perviously, any provider that had an ngOnDestroy lifecycle hook would be created eagerly. Now, only classes that are annotated with @Component, @Directive, @Pipe, @NgModule are eager. Providers only become eager if they are either directly or transitively injected into one of the above. This also makes all `useValue` providers eager, which should have no observable impact other than code size. EXPECTED IMPACT: Making providers eager was an incorrect behavior and never documented. Also, providers that are used by a directive / pipe / ngModule stay eager. So the impact should be rather small. Fixes #14552
This commit is contained in:

committed by
Chuck Jazdzewski

parent
0aad270267
commit
2c5a671341
@ -462,9 +462,10 @@ function _resolveProviders(
|
||||
(<CompileTypeMetadata>provider.token.identifier).lifecycleHooks ?
|
||||
(<CompileTypeMetadata>provider.token.identifier).lifecycleHooks :
|
||||
[];
|
||||
const isUseValue = !(provider.useClass || provider.useExisting || provider.useFactory);
|
||||
resolvedProvider = new ProviderAst(
|
||||
provider.token, provider.multi, eager || lifecycleHooks.length > 0, [provider],
|
||||
providerType, lifecycleHooks, sourceSpan);
|
||||
provider.token, provider.multi, eager || isUseValue, [provider], providerType,
|
||||
lifecycleHooks, sourceSpan);
|
||||
targetProvidersByToken.set(tokenReference(provider.token), resolvedProvider);
|
||||
} else {
|
||||
if (!provider.multi) {
|
||||
|
Reference in New Issue
Block a user