MCPcopy Create free account
hub / github.com/angular/angular / renderInternal

Function renderInternal

packages/platform-server/src/utils.ts:197–263  ·  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 if (platformRef.destroyed || applicationRef.destroyed) {
202 return '';
203 }
204
205 const platformState = platformRef.injector.get(PlatformState);
206 prepareForHydration(platformState, applicationRef);
207 appendServerContextInfo(applicationRef);
208
209 // Run any BEFORE_APP_SERIALIZED callbacks just before rendering to string.
210 const environmentInjector = applicationRef.injector;
211 const errorHandler = environmentInjector.get(INTERNAL_APPLICATION_ERROR_HANDLER);
212 const callbacks = environmentInjector.get(BEFORE_APP_SERIALIZED, null);
213 if (callbacks) {
214 const asyncCallbacks: Promise<void>[] = [];
215 for (const callback of callbacks) {
216 try {
217 const callbackResult = callback();
218 if (callbackResult) {
219 asyncCallbacks.push(callbackResult);
220 }
221 } catch (e) {
222 // Delegate to the application's ErrorHandler so custom handlers
223 // (e.g. Sentry) are notified, rather than writing directly to console.
224 if (!environmentInjector.destroyed) {
225 errorHandler(e);
226 }
227 }
228 }
229
230 if (asyncCallbacks.length) {
231 if (platformRef.destroyed || applicationRef.destroyed) {
232 void Promise.allSettled(asyncCallbacks);
233 return '';
234 }
235
236 const settled = await new Promise<PromiseSettledResult<void>[] | null>((resolve) => {
237 const unregisterDestroy = applicationRef.onDestroy(() => {
238 resolve(null);
239 });
240 Promise.allSettled(asyncCallbacks).then((results) => {
241 unregisterDestroy();
242 resolve(results);
243 });
244 });
245
246 if (settled === null) {
247 return '';
248 }
249
250 for (const result of settled) {
251 if (result.status === 'rejected' && !environmentInjector.destroyed) {
252 errorHandler(result.reason);
253 }
254 }

Callers 3

utils_spec.tsFile · 0.90
renderModuleFunction · 0.85
renderApplicationFunction · 0.85

Calls 11

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

Tested by

no test coverage detected