Skip to content

Commit 4387b37

Browse files
AndrewKushnirthePunderWoman
authored andcommitted
refactor(router): drop special handling of the OutletInjector (#58351)
This commit updates the OutletInjector and related code to avoid special handling of that injector. The main code that had special handling was refactored to no longer require is in #56763, this commit completes the cleanup. PR Close #58351
1 parent c1a1b1c commit 4387b37

File tree

3 files changed

+2
-46
lines changed

3 files changed

+2
-46
lines changed

packages/core/src/render3/util/injector_discovery_utils.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@ import {TContainerNode, TElementContainerNode, TElementNode, TNode} from '../int
3636
import {RElement} from '../interfaces/renderer_dom';
3737
import {INJECTOR, LView, TVIEW} from '../interfaces/view';
3838

39-
import {
40-
getParentInjectorIndex,
41-
getParentInjectorView,
42-
hasParentInjector,
43-
isRouterOutletInjector,
44-
} from './injector_utils';
39+
import {getParentInjectorIndex, getParentInjectorView, hasParentInjector} from './injector_utils';
4540
import {getNativeByTNode} from './view_utils';
4641

4742
/**
@@ -601,16 +596,7 @@ function getInjectorResolutionPathHelper(
601596
*/
602597
function getInjectorParent(injector: Injector): Injector | null {
603598
if (injector instanceof R3Injector) {
604-
const parent = injector.parent;
605-
if (isRouterOutletInjector(parent)) {
606-
// This is a special case for a `ChainedInjector` instance, which represents
607-
// a combination of a Router's `OutletInjector` and an EnvironmentInjector,
608-
// which represents a `@defer` block. Since the `OutletInjector` doesn't store
609-
// any tokens itself, we point to the parent injector instead. See the
610-
// `OutletInjector.__ngOutletInjector` field for additional information.
611-
return (parent as ChainedInjector).parentInjector;
612-
}
613-
return parent;
599+
return injector.parent;
614600
}
615601

616602
let tNode: TElementNode | TContainerNode | TElementContainerNode | null;

packages/core/src/render3/util/injector_utils.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,3 @@ export function getParentInjectorView(location: RelativeInjectorLocation, startV
6262
}
6363
return parentView;
6464
}
65-
66-
/**
67-
* Detects whether an injector is an instance of a `ChainedInjector`,
68-
* created based on the `OutletInjector`.
69-
*/
70-
export function isRouterOutletInjector(currentInjector: Injector): boolean {
71-
return (
72-
currentInjector instanceof ChainedInjector &&
73-
typeof (currentInjector.injector as any).__ngOutletInjector === 'function'
74-
);
75-
}

packages/router/src/directives/router_outlet.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -409,25 +409,6 @@ export class RouterOutlet implements OnDestroy, OnInit, RouterOutletContract {
409409
}
410410

411411
class OutletInjector implements Injector {
412-
/**
413-
* This injector has a special handing for the `ActivatedRoute` and
414-
* `ChildrenOutletContexts` tokens: it returns corresponding values for those
415-
* tokens dynamically. This behavior is different from the regular injector logic,
416-
* when we initialize and store a value, which is later returned for all inject
417-
* requests.
418-
*
419-
* In some cases (e.g. when using `@defer`), this dynamic behavior requires special
420-
* handling. This function allows to identify an instance of the `OutletInjector` and
421-
* create an instance of it without referring to the class itself (so this logic can
422-
* be invoked from the `core` package). This helps to retain dynamic behavior for the
423-
* mentioned tokens.
424-
*
425-
* Note: it's a temporary solution and we should explore how to support this case better.
426-
*/
427-
private __ngOutletInjector(parentInjector: Injector) {
428-
return new OutletInjector(this.route, this.childContexts, parentInjector, this.outletData);
429-
}
430-
431412
constructor(
432413
private route: ActivatedRoute,
433414
private childContexts: ChildrenOutletContexts,

0 commit comments

Comments
 (0)