Skip to content

Commit ef87cb7

Browse files
committed
eliminate possibility of race condition for new ab-testing
1 parent 2b5accc commit ef87cb7

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

dotcom-rendering/src/client/abTesting.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,19 @@ const getClientParticipations = (): ABParticipations => {
2929

3030
return {};
3131
};
32-
const initABTesting = (): void => {
33-
const { serverSideABTests } = window.guardian.config;
34-
35-
const clientSideABTests = getClientParticipations();
3632

37-
const participations = {
38-
...clientSideABTests,
39-
...serverSideABTests,
33+
const getABTestParticipations = (): ABParticipations => {
34+
return {
35+
...getClientParticipations(),
36+
...window.guardian.config.serverSideABTests,
4037
};
38+
};
39+
40+
const initABTesting = (): void => {
41+
const participations = getABTestParticipations();
4142

4243
window.guardian.modules.abTests = {
43-
getParticipations: () => participations,
44+
getParticipations: getABTestParticipations,
4445
isUserInTest: (testId: string) => {
4546
return !isUndefined(participations[testId]);
4647
},
@@ -50,4 +51,4 @@ const initABTesting = (): void => {
5051
};
5152
};
5253

53-
export { initABTesting };
54+
export { initABTesting, getABTestParticipations };

dotcom-rendering/src/experiments/lib/beta-ab-tests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { isUndefined } from '@guardian/libs';
2+
import { getABTestParticipations } from '../../client/abTesting';
23

34
export interface BetaABTestAPI {
45
getParticipations: () => ABParticipations;
@@ -55,8 +56,7 @@ export class BetaABTests implements BetaABTestAPI {
5556
if (isServer) {
5657
this.participations = serverSideABTests;
5758
} else {
58-
this.participations =
59-
window.guardian.modules.abTests?.getParticipations() ?? {};
59+
this.participations = getABTestParticipations();
6060
}
6161
}
6262

0 commit comments

Comments
 (0)