MCPcopy
hub / github.com/angular/angular / renderInternal

Function renderInternal

packages/platform-server/src/utils.ts:197–234  ·  view source on GitHub ↗
(
  platformRef: PlatformRef,
  applicationRef: ApplicationRef,
)

Source from the content-addressed store, hash-verified

195 * @returns A promise that resolves to the rendered string.
196 */
197export async function renderInternal(
198 platformRef: PlatformRef,
199 applicationRef: ApplicationRef,
200): Promise<string> {
201 const platformState = platformRef.injector.get(PlatformState);
202 prepareForHydration(platformState, applicationRef);
203 appendServerContextInfo(applicationRef);
204
205 // Run any BEFORE_APP_SERIALIZED callbacks just before rendering to string.
206 const environmentInjector = applicationRef.injector;
207 const errorHandler = environmentInjector.get(INTERNAL_APPLICATION_ERROR_HANDLER);
208 const callbacks = environmentInjector.get(BEFORE_APP_SERIALIZED, null);
209 if (callbacks) {
210 const asyncCallbacks: Promise<void>[] = [];
211 for (const callback of callbacks) {
212 try {
213 const callbackResult = callback();
214 if (callbackResult) {
215 asyncCallbacks.push(callbackResult);
216 }
217 } catch (e) {
218 // Delegate to the application's ErrorHandler so custom handlers
219 // (e.g. Sentry) are notified, rather than writing directly to console.
220 errorHandler(e);
221 }
222 }
223
224 if (asyncCallbacks.length) {
225 for (const result of await Promise.allSettled(asyncCallbacks)) {
226 if (result.status === 'rejected') {
227 errorHandler(result.reason);
228 }
229 }
230 }
231 }
232
233 return platformState.renderToString();
234}
235
236/**
237 * Destroy the application in a macrotask, this allows pending promises to be settled and errors

Callers 2

renderModuleFunction · 0.85
renderApplicationFunction · 0.85

Calls 8

prepareForHydrationFunction · 0.85
appendServerContextInfoFunction · 0.85
allSettledMethod · 0.80
renderToStringMethod · 0.80
getMethod · 0.65
callbackFunction · 0.50
errorHandlerFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…