fix(upgrade): correctly handle nested downgraded components with downgradeModule()
(#27217)
Previously, nested downgraded components would not be created/destroyed inside the Angular zone (as they should) and they would not be wired up correctly for change detection. This commit ensures that ngUpgrade correctly detects whether this is an ngUpgradeLite app (i.e. one using `downgradeModule()` instead of `UpgradeModule`) and appropriately handles components, even if they are nested inside other downgraded components. Fixes #22581 Closes #22869 Closes #27083 PR Close #27217
This commit is contained in:

committed by
Matias Niemelä

parent
8a7498e0ef
commit
326b464d20
@ -86,8 +86,9 @@ export function downgradeComponent(info: {
|
||||
// NOTE: This is not needed, when using `UpgradeModule`, because `$digest()` will be run
|
||||
// inside the Angular zone (except if explicitly escaped, in which case we shouldn't
|
||||
// force it back in).
|
||||
let isNgUpgradeLite = false;
|
||||
let wrapCallback = <T>(cb: () => T) => cb;
|
||||
const isNgUpgradeLite = getUpgradeAppType($injector) === UpgradeAppType.Lite;
|
||||
const wrapCallback: <T>(cb: () => T) => typeof cb =
|
||||
!isNgUpgradeLite ? cb => cb : cb => () => NgZone.isInAngularZone() ? cb() : ngZone.run(cb);
|
||||
let ngZone: NgZone;
|
||||
|
||||
return {
|
||||
@ -112,7 +113,6 @@ export function downgradeComponent(info: {
|
||||
validateInjectionKey($injector, downgradedModule, lazyModuleRefKey, attemptedAction);
|
||||
|
||||
const lazyModuleRef = $injector.get(lazyModuleRefKey) as LazyModuleRef;
|
||||
isNgUpgradeLite = getUpgradeAppType($injector) === UpgradeAppType.Lite;
|
||||
parentInjector = lazyModuleRef.injector || lazyModuleRef.promise as Promise<Injector>;
|
||||
}
|
||||
|
||||
@ -149,8 +149,6 @@ export function downgradeComponent(info: {
|
||||
const downgradeFn = !isNgUpgradeLite ? doDowngrade : (injector: Injector) => {
|
||||
if (!ngZone) {
|
||||
ngZone = injector.get(NgZone);
|
||||
wrapCallback = <T>(cb: () => T) => () =>
|
||||
NgZone.isInAngularZone() ? cb() : ngZone.run(cb);
|
||||
}
|
||||
|
||||
wrapCallback(() => doDowngrade(injector))();
|
||||
|
Reference in New Issue
Block a user