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

Function annotateHostElementForHydration

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

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