MCPcopy Index your code
hub / github.com/angular/angular / withDomHydration

Function withDomHydration

packages/core/src/hydration/api.ts:192–306  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

190 * configure or change anything in NgUniversal to enable the feature.
191 */
192export function withDomHydration(): EnvironmentProviders {
193 const providers: Provider[] = [
194 {
195 provide: IS_HYDRATION_DOM_REUSE_ENABLED,
196 useFactory: () => {
197 let isEnabled = true;
198 if (typeof ngServerMode === 'undefined' || !ngServerMode) {
199 // On the client, verify that the server response contains
200 // hydration annotations. Otherwise, keep hydration disabled.
201 const transferState = inject(TransferState, {optional: true});
202 isEnabled = !!transferState?.get(NGH_DATA_KEY, null);
203 }
204 if (isEnabled) {
205 performanceMarkFeature('NgHydration');
206 }
207 return isEnabled;
208 },
209 },
210 {
211 provide: ENVIRONMENT_INITIALIZER,
212 useValue: () => {
213 // i18n support is enabled by calling withI18nSupport(), but there's
214 // no way to turn it off (e.g. for tests), so we turn it off by default.
215 setIsI18nHydrationSupportEnabled(false);
216
217 if (typeof ngServerMode !== 'undefined' && ngServerMode) {
218 // Since this function is used across both server and client,
219 // make sure that the runtime code is only added when invoked
220 // on the client (see the `enableHydrationRuntimeSupport` function
221 // call below).
222 return;
223 }
224
225 const doc = inject(DOCUMENT);
226 if (inject(IS_HYDRATION_DOM_REUSE_ENABLED)) {
227 verifySsrContentsIntegrity(doc);
228 enableHydrationRuntimeSupport();
229 } else if (
230 typeof ngDevMode !== 'undefined' &&
231 ngDevMode &&
232 !isClientRenderModeEnabled(doc)
233 ) {
234 const console = inject(Console);
235 const message = formatRuntimeError(
236 RuntimeErrorCode.MISSING_HYDRATION_ANNOTATIONS,
237 'Angular hydration was requested on the client, but there was no ' +
238 'serialized information present in the server response, ' +
239 'thus hydration was not enabled. ' +
240 'Make sure the `provideClientHydration()` is included into the list ' +
241 'of providers in the server part of the application configuration.',
242 );
243 console.warn(message);
244 }
245 },
246 multi: true,
247 },
248 ];
249

Callers 1

provideClientHydrationFunction · 0.85

Calls 15

injectFunction · 0.90
performanceMarkFeatureFunction · 0.90
formatRuntimeErrorFunction · 0.90
cleanupDehydratedViewsFunction · 0.90
makeEnvironmentProvidersFunction · 0.90
whenStableWithTimeoutFunction · 0.85
printHydrationStatsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…