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

Function annotateHostElementForHydration

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

* Annotates component host element for hydration: * - by either adding the `ngh` attribute and collecting hydration-related info * for the serialization and transferring to the client * - or by adding the `ngSkipHydration` attribute in case Angular detects that * component contents is not co

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

Source from the content-addressed store, hash-verified

818 * or `null` when a given component can not be serialized.
819 */
820function annotateHostElementForHydration(
821 element: RElement,
822 lView: LView,
823 parentDeferBlockId: string | null,
824 context: HydrationContext,
825): number | null {
826 const renderer = lView[RENDERER];
827 if (
828 (hasI18n(lView) && !isI18nHydrationSupportEnabled()) ||
829 componentUsesShadowDomEncapsulation(lView)
830 ) {
831 // Attach the skip hydration attribute if this component:
832 // - either has i18n blocks, since hydrating such blocks is not yet supported
833 // - or uses ShadowDom view encapsulation, since Domino doesn't support
834 // shadow DOM, so we can not guarantee that client and server representations
835 // would exactly match
836 renderer.setAttribute(element, SKIP_HYDRATION_ATTR_NAME, '');
837 return null;
838 } else {
839 const ngh = serializeLView(lView, parentDeferBlockId, context);
840 const index = context.serializedViewCollection.add(ngh);
841 renderer.setAttribute(element, NGH_ATTR_NAME, index.toString());
842 return index;
843 }
844}
845
846/**
847 * Annotates defer block comment node for hydration:

Callers 3

serializeLViewFunction · 0.85

Calls 7

hasI18nFunction · 0.90
serializeLViewFunction · 0.85
setAttributeMethod · 0.65
addMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…