* Annotates root level LContainer for hydration. This happens when a root component * injects ViewContainerRef, thus making the component an anchor for a view container. * This function serializes the component itself as well as all views from the view * container.
(lContainer: LContainer, context: HydrationContext)
| 197 | * container. |
| 198 | */ |
| 199 | function annotateLContainerForHydration(lContainer: LContainer, context: HydrationContext) { |
| 200 | const componentLView = unwrapLView(lContainer[HOST]) as LView<unknown>; |
| 201 | |
| 202 | // Serialize the root component itself. |
| 203 | const componentLViewNghIndex = annotateComponentLViewForHydration(componentLView, context); |
| 204 | |
| 205 | if (componentLViewNghIndex === null) { |
| 206 | // Component was not serialized (for example, if hydration was skipped by adding |
| 207 | // the `ngSkipHydration` attribute or this component uses i18n blocks in the template, |
| 208 | // but `withI18nSupport()` was not added), avoid annotating host element with the `ngh` |
| 209 | // attribute. |
| 210 | return; |
| 211 | } |
| 212 | |
| 213 | const hostElement = unwrapRNode(componentLView[HOST]!) as HTMLElement; |
| 214 | |
| 215 | // Serialize all views within this view container. |
| 216 | const rootLView = lContainer[PARENT]; |
| 217 | const rootLViewNghIndex = annotateHostElementForHydration(hostElement, rootLView, null, context); |
| 218 | |
| 219 | const renderer = componentLView[RENDERER]; |
| 220 | |
| 221 | // For cases when a root component also acts as an anchor node for a ViewContainerRef |
| 222 | // (for example, when ViewContainerRef is injected in a root component), there is a need |
| 223 | // to serialize information about the component itself, as well as an LContainer that |
| 224 | // represents this ViewContainerRef. Effectively, we need to serialize 2 pieces of info: |
| 225 | // (1) hydration info for the root component itself and (2) hydration info for the |
| 226 | // ViewContainerRef instance (an LContainer). Each piece of information is included into |
| 227 | // the hydration data (in the TransferState object) separately, thus we end up with 2 ids. |
| 228 | // Since we only have 1 root element, we encode both bits of info into a single string: |
| 229 | // ids are separated by the `|` char (e.g. `10|25`, where `10` is the ngh for a component view |
| 230 | // and 25 is the `ngh` for a root view which holds LContainer). |
| 231 | const finalIndex = `${componentLViewNghIndex}|${rootLViewNghIndex}`; |
| 232 | renderer.setAttribute(hostElement, NGH_ATTR_NAME, finalIndex); |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Annotates all components bootstrapped in a given ApplicationRef |
no test coverage detected
searching dependent graphs…