refactor(core): store segment heads for empty comtainers (#49455)

This commit updates the logic to store references to the comment (anchor) node as a segment head, when a container is empty (no views). Previously, the logic verified whether a container is non-empty and only stored segment head in this case. The problem is that the ViewContainerRef later on uses the segment head to start the DOM lookup and as a result, the process can not be started, since we have `null`. Now the segment head reference would point to a comment node (the anchor node) and ViewContainerRef would be able to start the lookup process. For empty views, the segment head would become an anchor of the container (which is exactly what we need).

PR Close #49455
This commit is contained in:
Andrew Kushnir
2023-03-16 16:25:05 -07:00
committed by Pawel Kozlowski
parent ced237693a
commit f30a4072cd
2 changed files with 2 additions and 8 deletions
@@ -186,10 +186,7 @@ function locateOrCreateElementContainerNode(
'Unexpected state: hydrating an <ng-container>, ' +
'but no hydration info is available.');
// If this container is non-empty, store the first node as a segment head,
// otherwise, this node is an anchor and segment head doesn't exist (thus `null`).
const segmentHead = ngContainerSize > 0 ? currentRNode : null;
setSegmentHead(hydrationInfo, index, segmentHead);
setSegmentHead(hydrationInfo, index, currentRNode);
comment = siblingAfter<RComment>(ngContainerSize, currentRNode)!;
if (ngDevMode) {
@@ -140,11 +140,8 @@ function locateOrCreateContainerAnchorImpl(
const currentRNode = locateNextRNode(hydrationInfo, tView, lView, tNode)!;
ngDevMode && validateNodeExists(currentRNode);
setSegmentHead(hydrationInfo, index, currentRNode);
const viewContainerSize = calcSerializedContainerSize(hydrationInfo, index);
// If this container is non-empty, store the first node as a segment head,
// otherwise, this node is an anchor and segment head doesn't exist (thus `null`).
const segmentHead = viewContainerSize > 0 ? currentRNode : null;
setSegmentHead(hydrationInfo, index, segmentHead);
const comment = siblingAfter<RComment>(viewContainerSize, currentRNode)!;
if (ngDevMode) {