Skip to content

Commit 49d5de4

Browse files
alan-agius4mmalerba
authored andcommitted
refactor(platform-server): simplify transfer state serialization tracking (#63525)
The logic to track if the transfer state has been serialized is simplified by removing the need for `APP_ID`. Instead of maintaining a `Set` of application IDs, a simple boolean flag is used. PR Close #63525
1 parent ee73dc9 commit 49d5de4

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

packages/platform-server/src/transfer_state.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import {
2020

2121
import {BEFORE_APP_SERIALIZED} from './tokens';
2222

23-
// Tracks whether the server-side application state for a given app ID has been serialized already.
24-
export const TRANSFER_STATE_SERIALIZED_FOR_APPID = new InjectionToken<Set<string>>(
25-
typeof ngDevMode === 'undefined' || ngDevMode ? 'TRANSFER_STATE_SERIALIZED_FOR_APPID' : '',
23+
/** Tracks whether the server-side application transfer state has already been serialized. */
24+
const TRANSFER_STATE_STATUS = new InjectionToken<{serialized: boolean}>(
25+
typeof ngDevMode === 'undefined' || ngDevMode ? 'TRANSFER_STATE_STATUS' : '',
2626
{
2727
providedIn: 'root',
28-
factory: () => new Set(),
28+
factory: () => ({serialized: false}),
2929
},
3030
);
3131

@@ -53,10 +53,9 @@ export function createScript(
5353
}
5454

5555
function warnIfStateTransferHappened(injector: Injector): void {
56-
const appId = injector.get(APP_ID);
57-
const appIdsWithTransferStateSerialized = injector.get(TRANSFER_STATE_SERIALIZED_FOR_APPID);
56+
const transferStateStatus = injector.get(TRANSFER_STATE_STATUS);
5857

59-
if (appIdsWithTransferStateSerialized.has(appId)) {
58+
if (transferStateStatus.serialized) {
6059
console.warn(
6160
`Angular detected an incompatible configuration, which causes duplicate serialization of the server-side application state.\n\n` +
6261
`This can happen if the server providers have been provided more than once using different mechanisms. For example:\n\n` +
@@ -65,7 +64,8 @@ function warnIfStateTransferHappened(injector: Injector): void {
6564
`To fix this, ensure that the \`provideServerRendering()\` function is the only provider used and remove the other(s).`,
6665
);
6766
}
68-
appIdsWithTransferStateSerialized.add(appId);
67+
68+
transferStateStatus.serialized = true;
6969
}
7070

7171
function serializeTransferStateFactory() {

0 commit comments

Comments
 (0)