(appRef: ApplicationRef, doc: Document)
| 241 | * @return event types that need to be replayed |
| 242 | */ |
| 243 | export function annotateForHydration(appRef: ApplicationRef, doc: Document) { |
| 244 | const injector = appRef.injector; |
| 245 | const isI18nHydrationEnabledVal = isI18nHydrationEnabled(injector); |
| 246 | const isIncrementalHydrationEnabledVal = isIncrementalHydrationEnabled(injector); |
| 247 | const serializedViewCollection = new SerializedViewCollection(); |
| 248 | const corruptedTextNodes = new Map<HTMLElement, TextNodeMarker>(); |
| 249 | const viewRefs = appRef._views; |
| 250 | const shouldReplayEvents = injector.get(IS_EVENT_REPLAY_ENABLED, EVENT_REPLAY_ENABLED_DEFAULT); |
| 251 | const eventTypesToReplay = { |
| 252 | regular: new Set<string>(), |
| 253 | capture: new Set<string>(), |
| 254 | }; |
| 255 | const deferBlocks = new Map<string, SerializedDeferBlock>(); |
| 256 | const appId = appRef.injector.get(APP_ID); |
| 257 | for (const viewRef of viewRefs) { |
| 258 | const lNode = getLNodeForHydration(viewRef); |
| 259 | |
| 260 | // An `lView` might be `null` if a `ViewRef` represents |
| 261 | // an embedded view (not a component view). |
| 262 | if (lNode !== null) { |
| 263 | const context: HydrationContext = { |
| 264 | serializedViewCollection, |
| 265 | corruptedTextNodes, |
| 266 | isI18nHydrationEnabled: isI18nHydrationEnabledVal, |
| 267 | isIncrementalHydrationEnabled: isIncrementalHydrationEnabledVal, |
| 268 | i18nChildren: new Map(), |
| 269 | eventTypesToReplay, |
| 270 | shouldReplayEvents, |
| 271 | appId, |
| 272 | deferBlocks, |
| 273 | }; |
| 274 | if (isLContainer(lNode)) { |
| 275 | annotateLContainerForHydration(lNode, context); |
| 276 | } else { |
| 277 | annotateComponentLViewForHydration(lNode, context); |
| 278 | } |
| 279 | insertCorruptedTextNodeMarkers(corruptedTextNodes, doc); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | // Note: we *always* include hydration info key and a corresponding value |
| 284 | // into the TransferState, even if the list of serialized views is empty. |
| 285 | // This is needed as a signal to the client that the server part of the |
| 286 | // hydration logic was setup and enabled correctly. Otherwise, if a client |
| 287 | // hydration doesn't find a key in the transfer state - an error is produced. |
| 288 | const serializedViews = serializedViewCollection.getAll(); |
| 289 | const transferState = injector.get(TransferState); |
| 290 | transferState.set(NGH_DATA_KEY, serializedViews); |
| 291 | |
| 292 | if (deferBlocks.size > 0) { |
| 293 | const blocks: {[key: string]: SerializedDeferBlock} = {}; |
| 294 | for (const [id, info] of deferBlocks.entries()) { |
| 295 | blocks[id] = info; |
| 296 | } |
| 297 | transferState.set(NGH_DEFER_BLOCKS_KEY, blocks); |
| 298 | } |
| 299 | |
| 300 | return eventTypesToReplay; |
no test coverage detected
searching dependent graphs…