Skip to content

Commit 01cf04c

Browse files
mheveryjasonaden
authored andcommitted
refactor(ivy): createNodeAtIndex links TNodes on first pass only (angular#30453)
PR Close angular#30453
1 parent 5c5cee9 commit 01cf04c

File tree

1 file changed

+19
-11
lines changed
  • packages/core/src/render3/instructions

1 file changed

+19
-11
lines changed

packages/core/src/render3/instructions/shared.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,9 @@ export function createNodeAtIndex(
253253
const lView = getLView();
254254
const tView = lView[TVIEW];
255255
const adjustedIndex = index + HEADER_OFFSET;
256-
257-
const previousOrParentTNode = getPreviousOrParentTNode();
258256
let tNode = tView.data[adjustedIndex] as TNode;
259257
if (tNode == null) {
258+
const previousOrParentTNode = getPreviousOrParentTNode();
260259
const isParent = getIsParent();
261260
const parent =
262261
isParent ? previousOrParentTNode : previousOrParentTNode && previousOrParentTNode.parent;
@@ -369,7 +368,8 @@ export function createEmbeddedViewAndNode<T>(
369368
*
370369
* Dynamically created views must store/retrieve their TViews differently from component views
371370
* because their template functions are nested in the template functions of their hosts, creating
372-
* closures. If their host template happens to be an embedded template in a loop (e.g. ngFor inside
371+
* closures. If their host template happens to be an embedded template in a loop (e.g. ngFor
372+
* inside
373373
* an ngFor), the nesting would mean we'd have multiple instances of the template function, so we
374374
* can't store TViews in the template function itself (as we do for comps). Instead, we store the
375375
* TView for dynamically created views on their host TNode, which only has one instance.
@@ -811,7 +811,8 @@ export function elementPropertyInternal<T>(
811811
savePropertyDebugData(tNode, lView, propName, lView[TVIEW].data, nativeOnly);
812812

813813
const renderer = loadRendererFn ? loadRendererFn(tNode, lView) : lView[RENDERER];
814-
// It is assumed that the sanitizer is only added when the compiler determines that the property
814+
// It is assumed that the sanitizer is only added when the compiler determines that the
815+
// property
815816
// is risky, so sanitization can be done without further checks.
816817
value = sanitizer != null ? (sanitizer(value, tNode.tagName || '', propName) as any) : value;
817818
if (isProceduralRenderer(renderer)) {
@@ -957,7 +958,8 @@ export function instantiateRootComponent<T>(
957958
function resolveDirectives(
958959
tView: TView, viewData: LView, directives: DirectiveDef<any>[] | null, tNode: TNode,
959960
localRefs: string[] | null): void {
960-
// Please make sure to have explicit type for `exportsMap`. Inferred type triggers bug in tsickle.
961+
// Please make sure to have explicit type for `exportsMap`. Inferred type triggers bug in
962+
// tsickle.
961963
ngDevMode && assertEqual(tView.firstTemplatePass, true, 'should run on first template pass only');
962964
const exportsMap: ({[key: string]: number} | null) = localRefs ? {'': -1} : null;
963965
if (directives) {
@@ -1383,7 +1385,8 @@ export function createLContainer(
13831385

13841386

13851387
/**
1386-
* Goes over dynamic embedded views (ones created through ViewContainerRef APIs) and refreshes them
1388+
* Goes over dynamic embedded views (ones created through ViewContainerRef APIs) and refreshes
1389+
* them
13871390
* by executing an associated template function.
13881391
*/
13891392
function refreshDynamicEmbeddedViews(lView: LView) {
@@ -1394,7 +1397,8 @@ function refreshDynamicEmbeddedViews(lView: LView) {
13941397
if (current[ACTIVE_INDEX] === -1 && isLContainer(current)) {
13951398
for (let i = CONTAINER_HEADER_OFFSET; i < current.length; i++) {
13961399
const dynamicViewData = current[i];
1397-
// The directives and pipes are not needed here as an existing view is only being refreshed.
1400+
// The directives and pipes are not needed here as an existing view is only being
1401+
// refreshed.
13981402
ngDevMode && assertDefined(dynamicViewData[TVIEW], 'TView must be allocated');
13991403
renderEmbeddedTemplate(dynamicViewData, dynamicViewData[TVIEW], dynamicViewData[CONTEXT] !);
14001404
}
@@ -1471,9 +1475,12 @@ function syncViewWithBlueprint(componentView: LView) {
14711475
* @returns The state passed in
14721476
*/
14731477
export function addToViewTree<T extends LView|LContainer>(lView: LView, lViewOrLContainer: T): T {
1474-
// TODO(benlesh/misko): This implementation is incorrect, because it always adds the LContainer to
1475-
// the end of the queue, which means if the developer retrieves the LContainers from RNodes out of
1476-
// order, the change detection will run out of order, as the act of retrieving the the LContainer
1478+
// TODO(benlesh/misko): This implementation is incorrect, because it always adds the LContainer
1479+
// to
1480+
// the end of the queue, which means if the developer retrieves the LContainers from RNodes out
1481+
// of
1482+
// order, the change detection will run out of order, as the act of retrieving the the
1483+
// LContainer
14771484
// from the RNode is what adds it to the queue.
14781485
if (lView[CHILD_HEAD]) {
14791486
lView[CHILD_TAIL] ![NEXT] = lViewOrLContainer;
@@ -1626,7 +1633,8 @@ export function checkNoChangesInRootView(lView: LView): void {
16261633
}
16271634
}
16281635

1629-
/** Checks the view of the component provided. Does not gate on dirty checks or execute doCheck. */
1636+
/** Checks the view of the component provided. Does not gate on dirty checks or execute doCheck.
1637+
*/
16301638
export function checkView<T>(hostView: LView, component: T) {
16311639
const hostTView = hostView[TVIEW];
16321640
const oldView = enterView(hostView, hostView[T_HOST]);

0 commit comments

Comments
 (0)