MCPcopy Create free account
hub / github.com/angular/angular / locateNextRNode

Function locateNextRNode

packages/core/src/hydration/node_lookup_utils.ts:120–180  ·  view source on GitHub ↗
(
  hydrationInfo: DehydratedView,
  tView: TView,
  lView: LView<unknown>,
  tNode: TNode,
)

Source from the content-addressed store, hash-verified

118 * @returns an RNode that represents a given tNode
119 */
120export function locateNextRNode<T extends RNode>(
121 hydrationInfo: DehydratedView,
122 tView: TView,
123 lView: LView<unknown>,
124 tNode: TNode,
125): T | null {
126 const noOffsetIndex = getNoOffsetIndex(tNode);
127 let native = locateI18nRNodeByIndex(hydrationInfo, noOffsetIndex);
128
129 if (native === undefined) {
130 const nodes = hydrationInfo.data[NODES];
131 if (nodes?.[noOffsetIndex]) {
132 // We know the exact location of the node.
133 native = locateRNodeByPath(nodes[noOffsetIndex], lView);
134 } else if (tView.firstChild === tNode) {
135 // We create a first node in this view, so we use a reference
136 // to the first child in this DOM segment.
137 native = hydrationInfo.firstChild;
138 } else {
139 // Locate a node based on a previous sibling or a parent node.
140 const previousTNodeParent = tNode.prev === null;
141 const previousTNode = (tNode.prev ?? tNode.parent)!;
142 ngDevMode &&
143 assertDefined(
144 previousTNode,
145 'Unexpected state: current TNode does not have a connection ' +
146 'to the previous node or a parent node.',
147 );
148 if (isFirstElementInNgContainer(tNode)) {
149 const noOffsetParentIndex = getNoOffsetIndex(tNode.parent!);
150 native = getSegmentHead(hydrationInfo, noOffsetParentIndex);
151 } else {
152 let previousRElement = getNativeByTNode(previousTNode, lView);
153 if (previousTNodeParent) {
154 native = getFirstChild(previousRElement as Node);
155 } else {
156 // If the previous node is an element, but it also has container info,
157 // this means that we are processing a node like `<div #vcrTarget>`, which is
158 // represented in the DOM as `<div></div>...<!--container-->`.
159 // In this case, there are nodes *after* this element and we need to skip
160 // all of them to reach an element that we are looking for.
161 const noOffsetPrevSiblingIndex = getNoOffsetIndex(previousTNode);
162 const segmentHead = getSegmentHead(hydrationInfo, noOffsetPrevSiblingIndex);
163 if (previousTNode.type === TNodeType.Element && segmentHead) {
164 const numRootNodesToSkip = calcSerializedContainerSize(
165 hydrationInfo,
166 noOffsetPrevSiblingIndex,
167 );
168 // `+1` stands for an anchor comment node after all the views in this container.
169 const nodesToSkip = numRootNodesToSkip + 1;
170 // First node after this segment.
171 native = siblingAfter(nodesToSkip, segmentHead);
172 } else {
173 native = getNextSibling(previousRElement as Node);
174 }
175 }
176 }
177 }

Calls 11

assertDefinedFunction · 0.90
getSegmentHeadFunction · 0.90
getNativeByTNodeFunction · 0.90
getFirstChildFunction · 0.90
getNextSiblingFunction · 0.90
getNoOffsetIndexFunction · 0.85
locateI18nRNodeByIndexFunction · 0.85
locateRNodeByPathFunction · 0.85
siblingAfterFunction · 0.85

Tested by

no test coverage detected