Skip to content

Commit 43677f9

Browse files
authored
Revert Sticky Sessions (#7)
* Disable Sticky Sessions by Default * Revert "Disable Sticky Sessions by Default" This reverts commit 4af9351. * Revert Sticky Sessions * 0.0.7
1 parent a2b7c16 commit 43677f9

File tree

4 files changed

+4
-33
lines changed

4 files changed

+4
-33
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"description": "Eppo SDK for client-side JavaScript applications",
55
"main": "dist/index.js",
66
"files": [

src/eppo-client.spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,6 @@ describe('EppoClient E2E test', () => {
168168
);
169169
});
170170

171-
it('uses the same assignment during the session, even if it changes after local storage update', async () => {
172-
expect(getInstance().getAssignment(sessionOverrideSubject, preloadedConfigExperiment)).toEqual(
173-
'preloaded-config-variation',
174-
);
175-
});
176-
177171
it('returns subject from overrides when enabled is true', () => {
178172
const experiment = 'experiment_5';
179173
window.localStorage.setItem(

src/eppo-client.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as md5 from 'md5';
22

33
import { IAssignmentEvent, IAssignmentLogger } from './assignment-logger';
4-
import { MAX_EVENT_QUEUE_SIZE, NULL_SENTINEL, SESSION_ASSIGNMENT_CONFIG_LOADED } from './constants';
4+
import { MAX_EVENT_QUEUE_SIZE } from './constants';
55
import { IExperimentConfiguration } from './experiment/experiment-configuration';
66
import { EppoLocalStorage } from './local-storage';
77
import { Rule } from './rule';
@@ -50,30 +50,16 @@ export default class EppoClient implements IEppoClient {
5050
getAssignment(subjectKey: string, experimentKey: string, subjectAttributes = {}): string {
5151
validateNotBlank(subjectKey, 'Invalid argument: subjectKey cannot be blank');
5252
validateNotBlank(experimentKey, 'Invalid argument: experimentKey cannot be blank');
53-
// If getAssignment was called when the latest configuration were still being downloaded
54-
// use the old assignment for the remainder of the session to avoid a flickering effect;
55-
// we don't want a subject to switch between 2 variations during the same session.
56-
const sessionOverrideKey = `${subjectKey}-${experimentKey}-session-override`;
57-
const sessionOverride = this.sessionStorage.get(sessionOverrideKey);
58-
if (sessionOverride) {
59-
if (sessionOverride === NULL_SENTINEL) {
60-
return null;
61-
}
62-
this.logAssignment(experimentKey, sessionOverride, subjectKey, subjectAttributes);
63-
return sessionOverride;
64-
}
6553
const experimentConfig = this.configurationStore.get<IExperimentConfiguration>(experimentKey);
6654
const allowListOverride = this.getSubjectVariationOverride(subjectKey, experimentConfig);
6755
if (allowListOverride) {
68-
this.setSessionOverrideIfLoadingConfigurations(sessionOverrideKey, allowListOverride);
6956
return allowListOverride;
7057
}
7158
if (
7259
!experimentConfig?.enabled ||
7360
!this.subjectAttributesSatisfyRules(subjectAttributes, experimentConfig.rules) ||
7461
!this.isInExperimentSample(subjectKey, experimentKey, experimentConfig)
7562
) {
76-
this.setSessionOverrideIfLoadingConfigurations(sessionOverrideKey, NULL_SENTINEL);
7763
return null;
7864
}
7965
const { variations, subjectShards } = experimentConfig;
@@ -82,7 +68,6 @@ export default class EppoClient implements IEppoClient {
8268
isShardInRange(shard, variation.shardRange),
8369
).name;
8470
this.logAssignment(experimentKey, assignedVariation, subjectKey, subjectAttributes);
85-
this.setSessionOverrideIfLoadingConfigurations(sessionOverrideKey, assignedVariation);
8671
return assignedVariation;
8772
}
8873

@@ -129,12 +114,6 @@ export default class EppoClient implements IEppoClient {
129114
}
130115
}
131116

132-
private setSessionOverrideIfLoadingConfigurations(overrideKey: string, assignmentValue: string) {
133-
if (this.sessionStorage.get(SESSION_ASSIGNMENT_CONFIG_LOADED) !== 'true') {
134-
this.sessionStorage.set(overrideKey, assignmentValue);
135-
}
136-
}
137-
138117
// eslint-disable-next-line @typescript-eslint/no-explicit-any
139118
private subjectAttributesSatisfyRules(subjectAttributes?: Record<string, any>, rules?: Rule[]) {
140119
if (!rules || rules.length === 0) {

src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ export async function init(config: IClientConfig): Promise<IEppoClient> {
5757
});
5858
EppoClient.instance.setLogger(config.assignmentLogger);
5959
const configurationRequestor = new ExperimentConfigurationRequestor(localStorage, httpClient);
60-
if (sessionStorage.get(SESSION_ASSIGNMENT_CONFIG_LOADED) !== 'true') {
61-
await configurationRequestor.fetchAndStoreConfigurations();
62-
sessionStorage.set(SESSION_ASSIGNMENT_CONFIG_LOADED, 'true');
63-
}
60+
await configurationRequestor.fetchAndStoreConfigurations();
61+
sessionStorage.set(SESSION_ASSIGNMENT_CONFIG_LOADED, 'true');
6462
return EppoClient.instance;
6563
}
6664

0 commit comments

Comments
 (0)