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

Function annotateHostElementForHydration

packages/core/src/hydration/annotate.ts:819–843  ·  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

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