From 1086572b0aa6c4e0e9a696ba596d3519ff3386c9 Mon Sep 17 00:00:00 2001 From: Ondrej Kosarko Date: Thu, 26 Nov 2026 15:43:24 +0100 Subject: [PATCH] Don't schedule live-region timers during SSR Every notification raised during server-side rendering is announced via LiveRegionService.addMessage(), which starts an RxJS timer to clear the message after liveRegion.messageTimeOutDurationMs (30 s by default). The timer runs inside the Angular zone, so the zone never becomes stable and the SSR response is only sent once it fires. This made /login?error=shibboleth-authentication-failed (the Shibboleth and OIDC login failure page, which raises a notification on init) take ~30 s to render instead of ~0.1 s. On the server, skip the live region entirely: there is no screen reader to announce to, and the browser announces the notification once the app boots client-side. --- .../live-region/live-region.service.spec.ts | 20 +++++++++++++++++++ .../shared/live-region/live-region.service.ts | 12 ++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/app/shared/live-region/live-region.service.spec.ts b/src/app/shared/live-region/live-region.service.spec.ts index b14fa7abaf2..ce5fd8a506c 100644 --- a/src/app/shared/live-region/live-region.service.spec.ts +++ b/src/app/shared/live-region/live-region.service.spec.ts @@ -17,6 +17,7 @@ describe('liveRegionService', () => { service = new LiveRegionService( new UUIDService(), accessibilitySettingsService, + 'browser', ); }); @@ -34,6 +35,25 @@ describe('liveRegionService', () => { }); }); + describe('addMessage on the server', () => { + beforeEach(() => { + service = new LiveRegionService( + new UUIDService(), + accessibilitySettingsService, + 'server', + ); + }); + + it('should not store the message nor schedule its removal, so SSR is not held up', fakeAsync(() => { + // fakeAsync fails the spec if a timer is still pending at the end + const uuid = service.addMessage('Message One'); + + expect(uuid).toBeTruthy(); + expect(service.getMessages()).toEqual([]); + expect(accessibilitySettingsService.getAsNumber).not.toHaveBeenCalled(); + })); + }); + describe('clearMessages', () => { it('should clear the messages', () => { expect(service.getMessages().length).toEqual(0); diff --git a/src/app/shared/live-region/live-region.service.ts b/src/app/shared/live-region/live-region.service.ts index 37f58a2795d..7f02bfea7f3 100644 --- a/src/app/shared/live-region/live-region.service.ts +++ b/src/app/shared/live-region/live-region.service.ts @@ -1,4 +1,5 @@ -import { Injectable } from '@angular/core'; +import { Inject, Injectable, PLATFORM_ID } from '@angular/core'; +import { isPlatformServer } from '@angular/common'; import { BehaviorSubject, map, Observable, switchMap, take, timer } from 'rxjs'; import { environment } from '../../../environments/environment'; import { UUIDService } from '../../core/shared/uuid.service'; @@ -18,6 +19,7 @@ export class LiveRegionService { constructor( protected uuidService: UUIDService, protected accessibilitySettingsService: AccessibilitySettingsService, + @Inject(PLATFORM_ID) protected platformId: string, ) { } @@ -67,6 +69,14 @@ export class LiveRegionService { */ addMessage(message: string): string { const uuid = this.uuidService.generate(); + + // Skip during server-side rendering: there is no screen reader to announce to, and the removal timer below + // would keep the Angular zone unstable, so the SSR response would only be sent once the timeout + // (30 s by default) has elapsed. The browser adds the message again after the app boots client-side. + if (isPlatformServer(this.platformId)) { + return uuid; + } + this.messages.push({ message, uuid }); this.getConfiguredMessageTimeOutMs().pipe(