* Annotate nodes for hydration and remove event dispatch script when not needed.
(platformState: PlatformState, applicationRef: ApplicationRef)
| 93 | * Annotate nodes for hydration and remove event dispatch script when not needed. |
| 94 | */ |
| 95 | function prepareForHydration(platformState: PlatformState, applicationRef: ApplicationRef): void { |
| 96 | const measuringLabel = 'prepareForHydration'; |
| 97 | startMeasuring(measuringLabel); |
| 98 | const environmentInjector = applicationRef.injector; |
| 99 | const doc = platformState.getDocument(); |
| 100 | |
| 101 | if (!environmentInjector.get(IS_HYDRATION_DOM_REUSE_ENABLED, false)) { |
| 102 | // Hydration is diabled, remove inlined event dispatch script. |
| 103 | // (which was injected by the build process) from the HTML. |
| 104 | removeEventDispatchScript(doc); |
| 105 | |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | appendSsrContentIntegrityMarker(doc); |
| 110 | |
| 111 | const eventTypesToReplay = annotateForHydration(applicationRef, doc); |
| 112 | if (eventTypesToReplay.regular.size || eventTypesToReplay.capture.size) { |
| 113 | insertEventRecordScript( |
| 114 | environmentInjector.get(APP_ID), |
| 115 | doc, |
| 116 | eventTypesToReplay, |
| 117 | environmentInjector.get(CSP_NONCE, null), |
| 118 | ); |
| 119 | } else { |
| 120 | // No events to replay, we should remove inlined event dispatch script |
| 121 | // (which was injected by the build process) from the HTML. |
| 122 | removeEventDispatchScript(doc); |
| 123 | } |
| 124 | stopMeasuring(measuringLabel); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Creates a marker comment node and append it into the `<body>`. |
no test coverage detected
searching dependent graphs…