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

Function serializeLContainer

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

* Serializes the lContainer data into a list of SerializedView objects, * that represent views within this lContainer. * * @param lContainer the lContainer we are serializing * @param tNode the TNode that contains info about this LContainer * @param lView that hosts this LContainer * @param pa

(
  lContainer: LContainer,
  tNode: TNode,
  lView: LView,
  parentDeferBlockId: string | null,
  context: HydrationContext,
)

Source from the content-addressed store, hash-verified

312 * @returns an array of the `SerializedView` objects
313 */
314function serializeLContainer(
315 lContainer: LContainer,
316 tNode: TNode,
317 lView: LView,
318 parentDeferBlockId: string | null,
319 context: HydrationContext,
320): SerializedContainerView[] {
321 const views: SerializedContainerView[] = [];
322 let lastViewAsString = '';
323
324 for (let i = CONTAINER_HEADER_OFFSET; i < lContainer.length; i++) {
325 let childLView = lContainer[i] as LView;
326
327 let template: string;
328 let numRootNodes: number;
329 let serializedView: SerializedContainerView | undefined;
330
331 if (isRootView(childLView)) {
332 // If this is a root view, get an LView for the underlying component,
333 // because it contains information about the view to serialize.
334 childLView = childLView[HEADER_OFFSET];
335
336 // If we have an LContainer at this position, this indicates that the
337 // host element was used as a ViewContainerRef anchor (e.g. a `ViewContainerRef`
338 // was injected within the component class). This case requires special handling.
339 if (isLContainer(childLView)) {
340 // Calculate the number of root nodes in all attached views and add 2 to account for the
341 // component's host node and the container's anchor node. i.e. in this scenario we'll have a
342 // layout that would look like this:
343 // `<app-root /><#VIEW1><#VIEW2>...<!--container-->`
344 numRootNodes = calcNumRootNodesInLContainer(childLView) + 2;
345
346 annotateLContainerForHydration(childLView, context);
347
348 const componentLView = unwrapLView(childLView[HOST]) as LView<unknown>;
349
350 serializedView = {
351 [TEMPLATE_ID]: componentLView[TVIEW].ssrId!,
352 [NUM_ROOT_NODES]: numRootNodes,
353 };
354 }
355 }
356
357 if (!serializedView) {
358 const childTView = childLView[TVIEW];
359
360 if (childTView.type === TViewType.Component) {
361 template = childTView.ssrId!;
362
363 // This is a component view, thus it has only 1 root node: the component
364 // host node itself (other nodes would be inside that host node).
365 numRootNodes = 1;
366 } else {
367 template = getSsrId(childTView);
368 numRootNodes = calcNumRootNodes(childTView, childLView, childTView.firstChild);
369 }
370
371 serializedView = {

Callers 1

serializeLViewFunction · 0.85

Calls 15

isRootViewFunction · 0.90
isLContainerFunction · 0.90
unwrapLViewFunction · 0.90
isDeferBlockFunction · 0.90
getLDeferBlockDetailsFunction · 0.90
getTDeferBlockDetailsFunction · 0.90
unwrapRNodeFunction · 0.90
validateNodeExistsFunction · 0.90
validateMatchingNodeFunction · 0.90

Tested by

no test coverage detected