MCPcopy Index your code
hub / github.com/angular/angular / serializeLView

Function serializeLView

packages/core/src/hydration/annotate.ts:549–744  ·  view source on GitHub ↗

* Serializes the lView data into a SerializedView object that will later be added * to the TransferState storage and referenced using the `ngh` attribute on a host * element. * * @param lView the lView we are serializing * @param context the hydration context * @returns the `SerializedView` ob

(
  lView: LView,
  parentDeferBlockId: string | null = null,
  context: HydrationContext,
)

Source from the content-addressed store, hash-verified

547 * @returns the `SerializedView` object containing the data to be added to the host node
548 */
549function serializeLView(
550 lView: LView,
551 parentDeferBlockId: string | null = null,
552 context: HydrationContext,
553): SerializedView {
554 const ngh: SerializedView = {};
555 const tView = lView[TVIEW];
556 const i18nChildren = getOrComputeI18nChildren(tView, context);
557 const nativeElementsToEventTypes = context.shouldReplayEvents
558 ? collectDomEventsInfo(tView, lView, context.eventTypesToReplay)
559 : null;
560 // Iterate over DOM element references in an LView.
561 for (let i = HEADER_OFFSET; i < tView.bindingStartIndex; i++) {
562 const tNode = tView.data[i];
563 const noOffsetIndex = i - HEADER_OFFSET;
564
565 // Attempt to serialize any i18n data for the given slot. We do this first, as i18n
566 // has its own process for serialization.
567 const i18nData = trySerializeI18nBlock(lView, i, context);
568 if (i18nData) {
569 ngh[I18N_DATA] ??= {};
570 ngh[I18N_DATA][noOffsetIndex] = i18nData.caseQueue;
571
572 for (const nodeNoOffsetIndex of i18nData.disconnectedNodes) {
573 appendDisconnectedNodeIndex(ngh, nodeNoOffsetIndex);
574 }
575
576 for (const nodeNoOffsetIndex of i18nData.disjointNodes) {
577 const tNode = tView.data[nodeNoOffsetIndex + HEADER_OFFSET] as TNode;
578 ngDevMode && assertTNode(tNode);
579 appendSerializedNodePath(ngh, tNode, lView, i18nChildren);
580 }
581
582 continue;
583 }
584
585 // Skip processing of a given slot in the following cases:
586 // - Local refs (e.g. <div #localRef>) take up an extra slot in LViews
587 // to store the same element. In this case, there is no information in
588 // a corresponding slot in TNode data structure.
589 // - When a slot contains something other than a TNode. For example, there
590 // might be some metadata information about a defer block or a control flow block.
591 if (!isTNodeShape(tNode)) {
592 continue;
593 }
594
595 // Skip any nodes that are in an i18n block but are considered detached (i.e. not
596 // present in the template). These nodes are disconnected from the DOM tree, and
597 // so we don't want to serialize any information about them.
598 if (isDetachedByI18n(tNode)) {
599 continue;
600 }
601
602 // Serialize information about template.
603 if (isLContainer(lView[i]) && tNode.tView) {
604 ngh[TEMPLATES] ??= {};
605 ngh[TEMPLATES][noOffsetIndex] = getSsrId(tNode.tView!);
606 }

Callers 2

serializeLContainerFunction · 0.85

Calls 15

getOrComputeI18nChildrenFunction · 0.90
collectDomEventsInfoFunction · 0.90
trySerializeI18nBlockFunction · 0.90
assertTNodeFunction · 0.90
isTNodeShapeFunction · 0.90
isDetachedByI18nFunction · 0.90
isLContainerFunction · 0.90
isDisconnectedNodeFunction · 0.90
isProjectionTNodeFunction · 0.90
isInSkipHydrationBlockFunction · 0.90
unwrapRNodeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…