fix(platform-server): prevent false warning for duplicate state serialization (#63525)

The `TRANSFER_STATE_SERIALIZED_FOR_APPID` provider was previously configured at the platform level, causing its state to be shared across all concurrent server-side rendering requests. This created a race condition where one request could see the `appId` from a different, concurrent request, leading to false warnings about duplicate state serialization.

This commit changes the provider's scope to ensure that each application instance gets its own unique state. This correctly isolates the serialization check to each individual request, resolving the issue of false warnings in concurrent environments.

Closes #63524

PR Close #63525
This commit is contained in:
Alan Agius
2025-09-01 07:50:22 +00:00
committed by Miles Malerba
parent e6949ad355
commit ee73dc9553
@@ -24,7 +24,7 @@ import {BEFORE_APP_SERIALIZED} from './tokens';
export const TRANSFER_STATE_SERIALIZED_FOR_APPID = new InjectionToken<Set<string>>(
typeof ngDevMode === 'undefined' || ngDevMode ? 'TRANSFER_STATE_SERIALIZED_FOR_APPID' : '',
{
providedIn: 'platform',
providedIn: 'root',
factory: () => new Set(),
},
);
@@ -52,7 +52,7 @@ export function createScript(
return script;
}
export function warnIfStateTransferHappened(injector: Injector): void {
function warnIfStateTransferHappened(injector: Injector): void {
const appId = injector.get(APP_ID);
const appIdsWithTransferStateSerialized = injector.get(TRANSFER_STATE_SERIALIZED_FOR_APPID);