( platformRef: PlatformRef, applicationRef: ApplicationRef, )
| 195 | * @returns A promise that resolves to the rendered string. |
| 196 | */ |
| 197 | export 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 |
no test coverage detected
searching dependent graphs…