MCPcopy
hub / github.com/angular/angular / ssr

Function ssr

packages/platform-server/test/hydration_utils.ts:246–277  ·  view source on GitHub ↗
(
  component: Type<unknown>,
  options: {
    doc?: string;
    envProviders?: Provider[];
    hydrationFeatures?: () => HydrationFeature<HydrationFeatureKind>[];
    enableHydration?: boolean;
  } = {},
)

Source from the content-addressed store, hash-verified

244 * @returns a promise containing the server rendered app as a string
245 */
246export async function ssr(
247 component: Type<unknown>,
248 options: {
249 doc?: string;
250 envProviders?: Provider[];
251 hydrationFeatures?: () => HydrationFeature<HydrationFeatureKind>[];
252 enableHydration?: boolean;
253 } = {},
254): Promise<string> {
255 try {
256 // Enter server mode for the duration of this function.
257 globalThis['ngServerMode'] = true;
258
259 const defaultHtml = DEFAULT_DOCUMENT;
260 const {enableHydration = true, envProviders = [], hydrationFeatures = () => []} = options;
261 const providers = [
262 ...envProviders,
263 provideServerRendering(),
264 enableHydration ? provideClientHydration(...hydrationFeatures()) : [],
265 ];
266
267 const bootstrap = (context: BootstrapContext) =>
268 bootstrapApplication(component, {providers}, context);
269
270 return await renderApplication(bootstrap, {
271 document: options?.doc ?? defaultHtml,
272 });
273 } finally {
274 // Leave server mode so the remaining test is back in "client mode".
275 globalThis['ngServerMode'] = undefined;
276 }
277}
278
279/**
280 * Verifies that there are no messages in a console.

Calls 4

provideClientHydrationFunction · 0.90
renderApplicationFunction · 0.90
provideServerRenderingFunction · 0.85
hydrationFeaturesFunction · 0.70

Tested by

no test coverage detected