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

Function serializeLContainer

packages/core/src/hydration/annotate.ts:314–481  ·  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 views in a given container
341 // and increment by one to account for an anchor node itself, i.e. in this
342 // scenario we'll have a layout that would look like this:
343 // `<app-root /><#VIEW1><#VIEW2>...<!--container-->`
344 // The `+1` is to capture the `<app-root />` element.
345 numRootNodes = calcNumRootNodesInLContainer(childLView) + 1;
346
347 annotateLContainerForHydration(childLView, context);
348
349 const componentLView = unwrapLView(childLView[HOST]) as LView<unknown>;
350
351 serializedView = {
352 [TEMPLATE_ID]: componentLView[TVIEW].ssrId!,
353 [NUM_ROOT_NODES]: numRootNodes,
354 };
355 }
356 }
357
358 if (!serializedView) {
359 const childTView = childLView[TVIEW];
360
361 if (childTView.type === TViewType.Component) {
362 template = childTView.ssrId!;
363
364 // This is a component view, thus it has only 1 root node: the component
365 // host node itself (other nodes would be inside that host node).
366 numRootNodes = 1;
367 } else {
368 template = getSsrId(childTView);
369 numRootNodes = calcNumRootNodes(childTView, childLView, childTView.firstChild);
370 }
371

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…