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

Function prepareI18nBlockForHydrationImpl

packages/core/src/hydration/i18n.ts:407–473  ·  view source on GitHub ↗
(
  lView: LView,
  index: number,
  parentTNode: TNode | null,
  subTemplateIndex: number,
)

Source from the content-addressed store, hash-verified

405}
406
407function prepareI18nBlockForHydrationImpl(
408 lView: LView,
409 index: number,
410 parentTNode: TNode | null,
411 subTemplateIndex: number,
412) {
413 const hydrationInfo = lView[HYDRATION];
414 if (!hydrationInfo) {
415 return;
416 }
417
418 if (
419 !isI18nHydrationSupportEnabled() ||
420 (parentTNode &&
421 (isI18nInSkipHydrationBlock(parentTNode) ||
422 isDisconnectedNode(hydrationInfo, parentTNode.index - HEADER_OFFSET)))
423 ) {
424 return;
425 }
426
427 const tView = lView[TVIEW];
428 const tI18n = tView.data[index] as TI18n;
429 ngDevMode &&
430 assertDefined(tI18n, 'Expected i18n data to be present in a given TView slot during hydration');
431
432 function findHydrationRoot() {
433 if (isRootTemplateMessage(subTemplateIndex)) {
434 // This is the root of an i18n block. In this case, our hydration root will
435 // depend on where our parent TNode (i.e. the block with i18n applied) is
436 // in the DOM.
437 ngDevMode && assertDefined(parentTNode, 'Expected parent TNode while hydrating i18n root');
438 const rootNode = locateNextRNode(hydrationInfo!, tView, lView, parentTNode!) as Node;
439
440 // If this i18n block is attached to an <ng-container>, then we want to begin
441 // hydrating directly with the RNode. Otherwise, for a TNode with a physical DOM
442 // element, we want to recurse into the first child and begin there.
443 return parentTNode!.type & TNodeType.ElementContainer ? rootNode : getFirstChild(rootNode);
444 }
445
446 // This is a nested template in an i18n block. In this case, the entire view
447 // is translated, and part of a dehydrated view in a container. This means that
448 // we can simply begin hydration with the first dehydrated child.
449 return hydrationInfo?.firstChild as Node;
450 }
451
452 const currentNode = findHydrationRoot();
453 ngDevMode && assertDefined(currentNode, 'Expected root i18n node during hydration');
454
455 const disconnectedNodes = initDisconnectedNodes(hydrationInfo) ?? new Set();
456 const i18nNodes = (hydrationInfo.i18nNodes ??= new Map<number, RNode | null>());
457 const caseQueue = [...(hydrationInfo.data[I18N_DATA]?.[index - HEADER_OFFSET] ?? [])];
458 const dehydratedIcuData = (hydrationInfo.dehydratedIcuData ??= new Map<
459 number,
460 DehydratedIcuData
461 >());
462
463 collectI18nNodesFromDom(
464 {hydrationInfo, lView, i18nNodes, disconnectedNodes, caseQueue, dehydratedIcuData},

Callers

nothing calls this directly

Calls 7

isDisconnectedNodeFunction · 0.90
assertDefinedFunction · 0.90
initDisconnectedNodesFunction · 0.90
findHydrationRootFunction · 0.85
collectI18nNodesFromDomFunction · 0.85

Tested by

no test coverage detected