fix(ssr): bootstrap standalone app for CommonEngine
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
Passing EnvironmentProviders via CommonEngine StaticProvider[] dropped provideZoneChangeDetection, causing ZoneStablePendingTask2 on render. Use bootstrapApplication + mergeApplicationConfig instead.
This commit is contained in:
1 parent
0b82cbb25f
commit
0a30980105
5 files changed
+34
-36
No files matched your search
@@ -5,7 +5,7 @@ import { CommonEngine } from '@angular/ssr/node';
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import { existsSync } from 'node:fs';
|
import { existsSync } from 'node:fs';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import AppServerModule from './src/main.server';
|
import bootstrap from './src/main.server';
|
||||||
|
|
||||||
const STRAVA_API_BASE = 'https://www.strava.com/api/v3';
|
const STRAVA_API_BASE = 'https://www.strava.com/api/v3';
|
||||||
const FACEIT_API_BASE = 'https://open.faceit.com';
|
const FACEIT_API_BASE = 'https://open.faceit.com';
|
||||||
@@ -230,11 +230,8 @@ export function app(): express.Express {
|
|||||||
|
|
||||||
commonEngine
|
commonEngine
|
||||||
.render({
|
.render({
|
||||||
bootstrap: AppServerModule.bootstrap,
|
bootstrap,
|
||||||
providers: [
|
providers: [{ provide: APP_BASE_HREF, useValue: baseUrl }],
|
||||||
...AppServerModule.providers,
|
|
||||||
{ provide: APP_BASE_HREF, useValue: baseUrl },
|
|
||||||
] as unknown as import('@angular/core').StaticProvider[],
|
|
||||||
documentFilePath: indexHtml,
|
documentFilePath: indexHtml,
|
||||||
url: `${protocol}://${headers.host}${originalUrl}`,
|
url: `${protocol}://${headers.host}${originalUrl}`,
|
||||||
publicPath: distFolder,
|
publicPath: distFolder,
|
||||||
@@ -262,4 +259,4 @@ if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
|
|||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AppServerModule.bootstrap;
|
export default bootstrap;
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { ApplicationConfig, mergeApplicationConfig } from '@angular/core';
|
||||||
|
import { provideServerRendering } from '@angular/platform-server';
|
||||||
|
import { appConfig } from './app.config';
|
||||||
|
|
||||||
|
const serverConfig: ApplicationConfig = {
|
||||||
|
providers: [provideServerRendering()],
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Browser + server providers for SSR bootstrap. */
|
||||||
|
export const config = mergeApplicationConfig(appConfig, serverConfig);
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
|
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
|
||||||
import { provideRouter } from '@angular/router';
|
import { provideRouter } from '@angular/router';
|
||||||
import { provideHttpClient, withInterceptors } from '@angular/common/http';
|
import {
|
||||||
|
provideHttpClient,
|
||||||
|
withFetch,
|
||||||
|
withInterceptors,
|
||||||
|
} from '@angular/common/http';
|
||||||
|
import { provideClientHydration } from '@angular/platform-browser';
|
||||||
import { routes } from './app.routes';
|
import { routes } from './app.routes';
|
||||||
import { apiInterceptor } from './core/interceptors/api.interceptor';
|
import { apiInterceptor } from './core/interceptors/api.interceptor';
|
||||||
|
|
||||||
@@ -8,7 +13,8 @@ export const appConfig: ApplicationConfig = {
|
|||||||
providers: [
|
providers: [
|
||||||
provideZoneChangeDetection({ eventCoalescing: true }),
|
provideZoneChangeDetection({ eventCoalescing: true }),
|
||||||
provideRouter(routes),
|
provideRouter(routes),
|
||||||
provideHttpClient(withInterceptors([apiInterceptor])),
|
provideHttpClient(withFetch(), withInterceptors([apiInterceptor])),
|
||||||
|
provideClientHydration(),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
+2
-12
@@ -1,12 +1,2 @@
|
|||||||
import { provideServerRendering } from '@angular/platform-server';
|
// Kept for older import paths; prefer src/main.server.ts.
|
||||||
import { AppComponent } from './app.component';
|
export { config as default } from './app.config.server';
|
||||||
import { appConfig } from './app.config';
|
|
||||||
|
|
||||||
export const AppServerModule = {
|
|
||||||
bootstrap: AppComponent,
|
|
||||||
providers: [
|
|
||||||
...appConfig.providers,
|
|
||||||
provideServerRendering(),
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
+10
-15
@@ -1,17 +1,12 @@
|
|||||||
export { AppServerModule as default } from './app/app.server';
|
import {
|
||||||
|
bootstrapApplication,
|
||||||
|
BootstrapContext,
|
||||||
|
} from '@angular/platform-browser';
|
||||||
|
import { AppComponent } from './app/app.component';
|
||||||
|
import { config } from './app/app.config.server';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Standalone SSR bootstrap for CommonEngine. */
|
||||||
|
const bootstrap = (context: BootstrapContext) =>
|
||||||
|
bootstrapApplication(AppComponent, config, context);
|
||||||
|
|
||||||
|
export default bootstrap;
|
||||||
Reference in new issue
Block a user