From 50a4140f3d1ebdd098204896275a5e41250e7403 Mon Sep 17 00:00:00 2001 From: sumeyye Date: Wed, 10 Dec 2025 11:19:15 +0300 Subject: [PATCH] update: ssr condition for the app state refresh process --- .../core/src/lib/utils/initial-utils.ts | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts b/npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts index ece0404dcb..414f4d0a31 100644 --- a/npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts +++ b/npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts @@ -1,7 +1,7 @@ import { registerLocaleData } from '@angular/common'; import { inject, Injector } from '@angular/core'; import { tap, catchError } from 'rxjs/operators'; -import { lastValueFrom, throwError } from 'rxjs'; +import { firstValueFrom, lastValueFrom, of, throwError, timeout } from 'rxjs'; import { ABP } from '../models/common'; import { Environment } from '../models/environment'; import { CurrentTenantDto } from '../proxy/volo/abp/asp-net-core/mvc/multi-tenancy/models'; @@ -10,10 +10,11 @@ import { EnvironmentService } from '../services/environment.service'; import { SessionStateService } from '../services/session-state.service'; import { CORE_OPTIONS } from '../tokens/options.token'; import { APP_INIT_ERROR_HANDLERS } from '../tokens/app-config.token'; +import { CHECK_AUTHENTICATION_STATE_FN_KEY } from '../tokens/check-authentication-state'; +import { APP_STARTED_WITH_SSR } from '../tokens/ssr-state.token'; import { getRemoteEnv } from './environment-utils'; import { parseTenantFromUrl } from './multi-tenancy-utils'; import { AuthService } from '../abstracts'; -import { CHECK_AUTHENTICATION_STATE_FN_KEY } from '../tokens/check-authentication-state'; import { noop } from './common-utils'; export async function getInitialData() { @@ -21,6 +22,7 @@ export async function getInitialData() { const environmentService = injector.get(EnvironmentService); const configState = injector.get(ConfigStateService); const options = injector.get(CORE_OPTIONS) as ABP.Root; + const appStartedWithSSR = injector.get(APP_STARTED_WITH_SSR); environmentService.setState(options.environment as Environment); await getRemoteEnv(injector, options.environment); @@ -49,8 +51,18 @@ export async function getInitialData() { return throwError(() => error); }), ); - // TODO: Not working with SSR - // await lastValueFrom(result$); + + if (appStartedWithSSR) { + await firstValueFrom( + result$.pipe( + timeout(0), + catchError(() => of(null)), + ), + ); + } else { + await lastValueFrom(result$); + } + await localeInitializer(injector); }